Example usage for javax.swing JTable setRowSelectionInterval

List of usage examples for javax.swing JTable setRowSelectionInterval

Introduction

In this page you can find the example usage for javax.swing JTable setRowSelectionInterval.

Prototype

public void setRowSelectionInterval(int index0, int index1) 

Source Link

Document

Selects the rows from index0 to index1, inclusive.

Usage

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();
            }
        }
    });
}