How to find Index of First Visible Row in JTable?

How do I find the Index of the First Visible Row in a JTable which is on a ScrollPane recieving its data through a TableModel?
[140 byte] By [ryanb586586] at [2007-9-26 2:21:40]
# 1

Well, here is one way... maybe it will give you some ideas because I don't care for the code :

[code]

double a = m_table.getVisibleRect().getX();

double b = m_table.getVisibleRect().getY();

int row;

if (0 == a && 0 == b)

{

//may need to check for empty table

row = 0;

}

else

{

double cellHeight = m_table.getCellRect(0, 0, true).getHeight();

double num = Math.floor( b / cellHeight );

// y is the top of the jtable visible rectangle and

// height is the top to the bottom of the cell rectangle

// so we will need to add one to the result

row = num + 1;

}

[/code

mmbc at 2007-6-29 9:27:11 > top of Java-index,Archived Forums,Swing...
# 2
or use myTable.rowAtPoint( myTable.getVisibleRect().getLocation() )
Titie at 2007-6-29 9:27:11 > top of Java-index,Archived Forums,Swing...