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

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

Description

scroll To Visible

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/* /*from   ww w  . j  a va 2s.  c o  m*/
 * Copyright (C) 2014 Center of Excellence in Information Assurance
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import javax.swing.JViewport;
import javax.swing.JTable;

import java.awt.Point;
import java.awt.Rectangle;

public class Main {
    public static void scrollToVisible(JTable table, int rowIndex,
            int vColIndex) {
        if (!(table.getParent() instanceof JViewport)) {
            return;
        }

        JViewport viewport = (JViewport) table.getParent();

        // This rectangle is relative to the table where the
        // northwest corner of cell (0,0) is always (0,0).
        Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);

        // The location of the viewport relative to the table
        Point pt = viewport.getViewPosition();

        // Translate the cell location so that it is relative
        // to the view, assuming the northwest corner of the
        // view is (0,0)
        rect.setLocation(rect.x - pt.x, rect.y - pt.y);

        // Scroll the area into view
        viewport.scrollRectToVisible(rect);
    }
}

Related

  1. scrollToVisible(JTable table, int rowIndex, int colIndex)
  2. scrollToVisible(JTable table, int rowIndex, int colIndex, boolean center)
  3. scrollToVisible(JTable table, int rowIndex, int vColIndex)
  4. scrollToVisible(JTable table, int rowIndex, int vColIndex)
  5. scrollToVisible(JTable table, int rowIndex, int vColIndex)
  6. scrollToVisible(JTable table, int rowIndex, int vColIndex)
  7. selectAndScroll(JTable table, int rowIndex)
  8. selectAndScrollToPosition(JTable table, int index0, int index1)
  9. selectRow(int row, JTable table, JScrollPane pane)