how do I preselect a row in Jtable / JScrollPane?

Hi

I want to preselect and show a row in a table of e.g. 1000 rows.

e.g. if I type in a value in a field, I want the table to automatically scroll, and show the row whose 1st column has a value that corresponds closest to what I typed.

I tried JTable.setRowSelectionInterval(i,j), but this only highlighted the row, and I had to scoll down the scollpane manually to find it.

Anyone have a suggestion?

regards

Arne

[463 byte] By [ajwk] at [2007-9-26 3:00:52]
# 1

JViewport has a method setViewPosition(p) that takes point p which will be viewport's top left corner. Since u know which row u want to select, getCellRect(row, column) ot JTable gives you cell's Rectangle. Take x and y from this rectangle create a point and use it in setViewPosition. getParent() of JTable directly returns u JViewport. so the code should be

JTable tabl;

/* table code

and finding row and column to be set as r and c;

*/

Rectangle ret = tabl.getCellRect(r,c,true);

Point p = new Point(ret.x,ret.y);

((JViewport)tabl.getParent()).setViewPosition(p);

Hope this helps.

National at 2007-6-29 10:58:23 > top of Java-index,Archived Forums,Swing...
# 2
tnx, it worked..Arne
ajwk at 2007-6-29 10:58:23 > top of Java-index,Archived Forums,Swing...