Java JTable Scroll scrollToSelectedRow(JTable table)

Here you can find the source of scrollToSelectedRow(JTable table)

Description

scroll To Selected Row

License

Apache License

Declaration

private static void scrollToSelectedRow(JTable table)

Method Source Code

    //package com.java2s;
    //License from project: Apache License 

    import javax.swing.*;

    import java.awt.*;

    public class Main {
        private static void scrollToSelectedRow(JTable table)
{
   JViewport viewport = (JViewport) table.getParent();
   Rectangle cellRectangle = table.getCellRect(table.getSelectedRow(), 0, true);
   Rectangle visibleRectangle = viewport.getVisibleRect();
   SwingUtilities.invokeLater(() -> table.scrollRectToVisible(new Rectangle(cellRectangle.x, cellRectangle.y, (int) visibleRectangle.getWidth(), (int) visibleRectangle.getHeight())));
}
    }/*from   www .j a  v a2s  .c om*/

Related

  1. scroll(JTable table, int rowIndex, int vColIndex)
  2. scrollToCenter(JTable table, int rowIndex, int vColIndex)
  3. scrollToLastSelectedRow(final JTable table)
  4. scrollToPosition(JTable table, int insertRow)
  5. scrollToRow(JTable table, int row)
  6. scrollToTableCell(JTable table, int rowIndex, int colIndex)
  7. scrollToVisible(final JTable table, final int rowIndex, final int vColIndex)
  8. scrollToVisible(final JTable table, final int rowIndex, final int vColIndex)
  9. scrollToVisible(final JTable table, int rowIndex, int vColIndex)