I have a Jtable. Upon accepting the row number entered by the user, the query results screen shall scroll down such that the entered row number is "at the top of the screen" of JTable.
The code i have used is:
//Dialog box to fetch row number from the user
rowNo = customDialog.getRowNum();
if (rowNo > 0)
{
//Scroll to the first row of jTable
jTable.scrollRectToVisible(jTable.getCellRect(0,0,true));
//Scroll such that entered row no. is at the top of the screen
jTable.setRowSelectionInterval(rowNo-1,rowNo-1);
int y1 = (rowNo-1) * jTable.getRowHeight();
int w1 = jTable.getWidth();
int h1 = jTable.getHeight();
jTable.scrollRectToVisible(new Rectangle(0,y1,w1,h1));
}
Using the above code is working fine except for one issue. My JTable screen accomdates 20 rows at once and on maximizing, 30 rows are visible. Assume there are total of 1700 rows, and the user enters 1699. If this is the scenario, we get the last screen but the row 1699 is not at the top of the screen. So my question is if the entered row number by the user is one among last 20 or 30 rows among the total number of rows, how to get this at the top of the screen of JTable.
Any help would be appreciated.
The code i have used is:
//Dialog box to fetch row number from the user
rowNo = customDialog.getRowNum();
if (rowNo > 0)
{
//Scroll to the first row of jTable
jTable.scrollRectToVisible(jTable.getCellRect(0,0,true));
//Scroll such that entered row no. is at the top of the screen
jTable.setRowSelectionInterval(rowNo-1,rowNo-1);
int y1 = (rowNo-1) * jTable.getRowHeight();
int w1 = jTable.getWidth();
int h1 = jTable.getHeight();
jTable.scrollRectToVisible(new Rectangle(0,y1,w1,h1));
}
Using the above code is working fine except for one issue. My JTable screen accomdates 20 rows at once and on maximizing, 30 rows are visible. Assume there are total of 1700 rows, and the user enters 1699. If this is the scenario, we get the last screen but the row 1699 is not at the top of the screen. So my question is if the entered row number by the user is one among last 20 or 30 rows among the total number of rows, how to get this at the top of the screen of JTable.
Any help would be appreciated.