Java JTable Row Visible getLastVisibleRow(JTable p_Table)

Here you can find the source of getLastVisibleRow(JTable p_Table)

Description

get Last Visible Row

License

Apache License

Declaration

public static int getLastVisibleRow(JTable p_Table) 

Method Source Code

//package com.java2s;
/*//from  www  .j av  a2s.  c o m
 * Copyright 2015 Matthew Aguirre
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.Point;

import javax.swing.JTable;

public class Main {
    public static int getLastVisibleRow(JTable p_Table) {
        Point p = p_Table.getVisibleRect().getLocation();
        p.y = p.y + p_Table.getVisibleRect().height - 1;
        int result = p_Table.rowAtPoint(p);
        if (result > 0) {
            return result;
        }

        // if there is no rows at this point,rowatpoint() return -1,
        // It means that there is not enough rows to fill the rectangle where
        // the table is displayed.
        // if this case we return getRowCount()-1 because
        // we are sure that the last row is visible
        if (p_Table.getVisibleRect().height > 0) {
            return p_Table.getRowCount() - 1;
        } else {
            return -1;
        }
    }
}

Related

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