List of usage examples for javax.swing JTable setRowSelectionInterval
public void setRowSelectionInterval(int index0, int index1)
index0
to index1
, inclusive. From source file:pl.otros.logview.gui.LogViewPanelWrapper.java
private void addRowScroller() { dataTableModel.addTableModelListener(new TableModelListener() { @Override/*from w w w .ja va 2 s.c om*/ public void tableChanged(final TableModelEvent e) { if (follow.isSelected() && e.getType() == TableModelEvent.INSERT) { final Runnable r = new Runnable() { @Override public void run() { try { JTable table = logViewPanel.getTable(); int row = table.getRowCount() - 1; if (row > 0) { Rectangle rect = table.getCellRect(row, 0, true); table.scrollRectToVisible(rect); table.clearSelection(); table.setRowSelectionInterval(row, row); } } catch (IllegalArgumentException iae) { // ignore..out of bounds iae.printStackTrace(); } } }; // Wait for JViewPort size update // TODO Find way to invoke this listener after viewport is notified about changes Runnable r2 = new Runnable() { @Override public void run() { try { Thread.sleep(300); } catch (InterruptedException ignore) { } SwingUtilities.invokeLater(r); } }; new Thread(r2).start(); } } }); }