int (@NotNull JTable table, @NotNull Rectangle visibleRect) { Point trailingPoint; if (table.getComponentOrientation().isLeftToRight()) { trailingPoint = new Point(visibleRect.x, visibleRect.y + visibleRect.height - 1); } else { trailingPoint = new Point(visibleRect.x + visibleRect.width, visibleRect.y + visibleRect.height - 1); } int row = table.rowAtPoint(trailingPoint); if (row >= 0) return row; // return the last row in the table // if there is no any row at the given point return table.getRowCount() - 1; }