Java JTable Scroll AutoScrollTable(final JTable table_packets)

Here you can find the source of AutoScrollTable(final JTable table_packets)

Description

Auto Scroll Table

License

Open Source License

Declaration

public static void AutoScrollTable(final JTable table_packets) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;

public class Main {
    public static void AutoScrollTable(final JTable table_packets) {
        TableModelListener l = new TableModelListener() {
            @Override/*w ww . j a  v  a2 s. com*/
            public void tableChanged(final TableModelEvent e) {
                if (e.getType() == TableModelEvent.INSERT) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            int viewRow = table_packets.convertRowIndexToView(e.getFirstRow());
                            table_packets.scrollRectToVisible(table_packets.getCellRect(viewRow, 0, true));
                        }
                    });
                }
            }
        };
        table_packets.getModel().addTableModelListener(l);
    }
}

Related

  1. addHorizontalScrollBar(JTable table, JScrollPane pane)
  2. createTableScrollPane(final JTable table)
  3. findScrollPane(JTable p_Table)
  4. getScrollPane(JTable myTable)
  5. makeTransparant(JTable table, JScrollPane scrollPane)