Example usage for javax.swing JTable getCellRect

List of usage examples for javax.swing JTable getCellRect

Introduction

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

Prototype

public Rectangle getCellRect(int row, int column, boolean includeSpacing) 

Source Link

Document

Returns a rectangle for the cell that lies at the intersection of row and column.

Usage

From source file:pl.otros.logview.gui.LogViewPanelWrapper.java

private void addRowScroller() {
    dataTableModel.addTableModelListener(new TableModelListener() {

        @Override/*  ww  w . j a  va  2 s  . com*/
        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();
            }
        }
    });
}