Java JTable Row Visible getLastVisibleRowIndex(JTable table)

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

Description

Returns the row index of the last visible row.

License

Open Source License

Declaration

public static int getLastVisibleRowIndex(JTable table) 

Method Source Code

//package com.java2s;
/*/*from  w ww . j a  v  a  2  s  .c  o m*/
 * Copyright (c) 2009 Albert Kurucz. 
 *
 * This file, Util.java is part of JTStand.
 *
 * JTStand is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JTStand 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with GTStand.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.ComponentOrientation;

import java.awt.Rectangle;

import javax.swing.JTable;

public class Main {
    /**
     * Returns the row index of the last visible row.
     */
    public static int getLastVisibleRowIndex(JTable table) {
        ComponentOrientation or = table.getComponentOrientation();
        Rectangle r = table.getVisibleRect();
        r.translate(0, (int) r.getHeight() - 1);
        if (or.isLeftToRight()) {
            r.translate((int) r.getWidth() - 1, 0);
            // The next if makes sure that we don't return -1 simply because
            // there is white space at the bottom of the table (ie, the display
            // area is larger than the table)
        }
        if (table.rowAtPoint(r.getLocation()) == -1) {
            if (getFirstVisibleRowIndex(table) == -1) {
                return -1;
            } else {
                return table.getModel().getRowCount() - 1;
            }
        }
        return table.rowAtPoint(r.getLocation());
    }

    /**
     * Returns the row index of the last visible row.
     */
    public static int getFirstVisibleRowIndex(JTable table) {
        ComponentOrientation or = table.getComponentOrientation();
        Rectangle r = table.getVisibleRect();
        if (!or.isLeftToRight()) {
            r.translate((int) r.getWidth() - 1, 0);
        }
        return table.rowAtPoint(r.getLocation());
    }
}

Related

  1. ensureRowVisible(JTable table, int row)
  2. getFirstVisibleRow(JTable p_Table)
  3. getFirstVisibleRowIndex(JTable table)
  4. getLastVisibleRow(JTable p_Table)
  5. getLastVisibleRow(JTable p_Table)
  6. getLeadingRow(JTable table, Rectangle visibleRect)
  7. getVisibleRowCount(JTable list)
  8. makeRowVisible(JTable table, int row)
  9. setupTableUI(JTable table, int visibleRows)