Java Utililty Methods JTable Scroll

List of utility methods to do JTable Scroll

Description

The list of methods to do JTable Scroll are organized into topic(s).

Method

voidaddHorizontalScrollBar(JTable table, JScrollPane pane)
Force l'ajout d'une scrollbar horizontale sur une JTable.
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
pane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
voidAutoScrollTable(final JTable table_packets)
Auto Scroll Table
TableModelListener l = new TableModelListener() {
    @Override
    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));
...
JScrollPanecreateTableScrollPane(final JTable table)
create Table Scroll Pane
table.setRowSorter(new TableRowSorter<>(table.getModel()));
return new JScrollPane(table);
JScrollPanefindScrollPane(JTable p_Table)
find Scroll Pane
return (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, p_Table);
JScrollPanegetScrollPane(JTable myTable)
get Scroll Pane
JScrollPane scroll = new JScrollPane(myTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
myTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
return scroll;
voidmakeTransparant(JTable table, JScrollPane scrollPane)
make Transparant
table.setOpaque(false);
((DefaultTableCellRenderer) table.getDefaultRenderer(Object.class)).setOpaque(false);
((DefaultTableCellRenderer) table.getDefaultRenderer(String.class)).setOpaque(false);
((JComponent) table.getDefaultRenderer(Boolean.class)).setOpaque(false);
scrollPane.setOpaque(false);
scrollPane.getViewport().setOpaque(false);
voidscroll(JTable table, int rowIndex, int vColIndex)
Scrolls view if it is located in a JViewport, so that the specified cell is displayed in the center.
if (!(table.getParent() instanceof JViewport)) {
    return;
JViewport viewport = (JViewport) table.getParent();
Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
Rectangle viewRect = viewport.getViewRect();
if (viewRect.intersects(rect)) {
    return;
...
voidscrollToCenter(JTable table, int rowIndex, int vColIndex)
scroll To Center
if (!(table.getParent() instanceof JViewport)) {
    return;
JViewport viewport = (JViewport) table.getParent();
Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
Rectangle viewRect = viewport.getViewRect();
rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y);
int centerX = (viewRect.width - rect.width) / 2;
...
voidscrollToLastSelectedRow(final JTable table)
scroll To Last Selected Row
if (table == null) {
    return;
int[] selectedRows = table.getSelectedRows();
if (selectedRows.length > 0) {
    scrollToVisible(table, selectedRows[selectedRows.length - 1], 0);
voidscrollToPosition(JTable table, int insertRow)
scroll To Position
Rectangle rectangle = table.getCellRect(insertRow, 1, true);
table.scrollRectToVisible(rectangle);