Java JTable Scroll scrollToVisible(final JTable table, int rowIndex, int vColIndex)

Here you can find the source of scrollToVisible(final JTable table, int rowIndex, int vColIndex)

Description

scroll To Visible

License

Open Source License

Declaration

public static void scrollToVisible(final JTable table, int rowIndex, int vColIndex) 

Method Source Code


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

import javax.swing.*;
import java.awt.*;

public class Main {
    public static void scrollToVisible(final JTable table, int rowIndex, int vColIndex) {
        if (table == null || !(table.getParent() instanceof JViewport)) {
            return;
        }/*from   w  w w . jav a 2s  .c om*/
        JViewport viewport = (JViewport) table.getParent();

        try {
            final Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
            Point pt = viewport.getViewPosition();
            rect.setLocation(rect.x - pt.x, rect.y - pt.y);
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    table.scrollRectToVisible(rect);
                }
            });
        } catch (Exception e) {
        }
    }
}

Related

  1. scrollToRow(JTable table, int row)
  2. scrollToSelectedRow(JTable table)
  3. scrollToTableCell(JTable table, int rowIndex, int colIndex)
  4. scrollToVisible(final JTable table, final int rowIndex, final int vColIndex)
  5. scrollToVisible(final JTable table, final int rowIndex, final int vColIndex)
  6. scrollToVisible(JTable table, int row, int col)
  7. scrollToVisible(JTable table, int row, int col)
  8. scrollToVisible(JTable table, int rowIndex, int colIndex)
  9. scrollToVisible(JTable table, int rowIndex, int colIndex, boolean center)