long currentScrollBarMax = 0;
//int lastRow = m_LogModel.getRowCount();
// check if the user has change the scrolling position
JScrollPane scrollPane = (JScrollPane) m_LogTable.getParent().getParent();
JScrollBar scrollbar = scrollPane.getVerticalScrollBar();
if (scrollbar != null) {
if (scrollbar.getMouseListeners().length == 1) {
scrollPane.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
m_UserScrollPosition = true;
}
});
scrollbar.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
m_UserScrollPosition = true;
}
@Override
public void mousePressed(MouseEvent e) {
m_UserScrollPosition = true;
}
});
}
currentScrollBarMax = scrollbar.getMaximum() - scrollbar.getSize().height - m_LogTable.getRowHeight();
m_LogModel.addRow(cols);
// check if the first row must be remove (memory handling issue)
if (m_LogModel.getRowCount() > MAX_ROWS) {
boolean wasFirstRowVisible = m_LogSorterTable.convertRowIndexToView(0) != -1;
m_LogModel.removeRow(0);
if (wasFirstRowVisible && m_UserScrollPosition) {
Rectangle visibleRect = m_LogTable.getVisibleRect();
if (!visibleRect.contains(0, 0)) {
visibleRect.y -= m_LogTable.getScrollableUnitIncrement(visibleRect, SwingConstants.VERTICAL, -1);
m_LogTable.scrollRectToVisible(visibleRect);
}
}
}
if (!m_UserScrollPosition) {
m_LogTable.scrollRectToVisible(
m_LogTable.getCellRect(m_LogTable.getRowCount() - 1, 0, true));
return;
} else if (scrollbar.getValue() >= currentScrollBarMax) {
m_LogTable.scrollRectToVisible(
m_LogTable.getCellRect(m_LogTable.getRowCount() - 1, 0, true));
m_UserScrollPosition = false;
return;
}