JTable - selected row in large table is not "visible"

B

Branko Kaucic

Hi all!

I want to select row in JTable that contains large table (not all rows
can be visible on the screen at once).
I use method

grid.getSelectionModel().setSelectionInterval(i,i);

that selects the row that I wish (row i), but if this row is in
"currently not shown part of table", table data is not scrolled (up or
down) such that just selected row would be visible.
What should I do, because this really bothers me:(

Regards,
B
 
B

Branko Kaucic

Hi!

I still haven't found out this problem yet :(
Have I missed the answer on news group? I hope not. If I am, I am sorry
and please could you answer again.

Thanks,
B
--
Hi all!

I want to select row in JTable that contains large table (not all rows
can be visible on the screen at once).
I use method

grid.getSelectionModel().setSelectionInterval(i,i);

that selects the row that I wish (row i), but if this row is in
"currently not shown part of table", table data is not scrolled (up or
down) such that just selected row would be visible.
What should I do, because this really bothers me:(

Regards,
B
 
Z

zero

Hi!

I still haven't found out this problem yet :(
Have I missed the answer on news group? I hope not. If I am, I am
sorry and please could you answer again.

Thanks,
B
--
Hi all!

I want to select row in JTable that contains large table (not all
rows can be visible on the screen at once).
I use method

grid.getSelectionModel().setSelectionInterval(i,i);

that selects the row that I wish (row i), but if this row is in
"currently not shown part of table", table data is not scrolled (up
or down) such that just selected row would be visible.
What should I do, because this really bothers me:(

Regards,
B

This is very Swing dependent, so you may have better luck in either
comp.lang.java.gui
or Sun's own Swing Forum at
http://forums.java.sun.com/forum.jspa?forumID=57

I think what you need to do is:

1. determine the height in pixels of one row in the JTable. There is a
method for this in JTable if I'm not mistaken. 2. calculate the height
in pixels of everything from the top of the table to the row that was
selected - ie rows*height 3. scroll the JScrollPane down (or up as the
case may be) to the selected row

I haven't tested this, but I think it should work. I don't know of an
easier way but there may be one. For that I refer you to the two
references I gave above.

Zero
 
R

Roedy Green

grid.getSelectionModel().setSelectionInterval(i,i)

You just want to make sure those selected rows are as visible as
possible, which might be impossible if the user has selected more than
a screenful.

You might want to simulate how the user would do it, first making the
first row visible then the last.

Keep in mind that your JTable lives in a JScrollPane. Perhaps someone
will come up with a better, way, but you could use
JScrollPane.getVerticalScrollBar().setValue().
 
Joined
May 26, 2008
Messages
2
Reaction score
0
Hi even i am facing the same problem.
Can anyone help me out. The above solution did not work.
I guess Branko Kaucic got the solution till now.
Branko can you guide me to solve the issue.

regards
Vivek Agnihotri
 
Last edited:
Joined
May 26, 2008
Messages
2
Reaction score
0
Page Up/Down is not working properly..

Hi all!

I want to select row in JTable that contains large table (not all rows
can be visible on the screen at once).
I use method

table.changeSelection(selectedRow, selectedRow, false,true );

that selects the row that I wish (row i), but if this row is in
"currently not shown part of table", table data is not scrolled (up or
down) such that just selected row would be visible.
What should I do, because this really bothers me :(
Please help me .. its urgent..
 
Joined
Dec 11, 2008
Messages
1
Reaction score
0
use table.scrollRectToVisible(table.getCellRect(row, column, false));
Got it from: forumsDOTjavaDOTnet/jive/thread.jspa?messageID=312347
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top