File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to move the selected row in Jtable to be the first row in the table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to move the selected row in Jtable to be the first row in the table" Watch "How to move the selected row in Jtable to be the first row in the table" New topic
Author

How to move the selected row in Jtable to be the first row in the table

S. Osbourne
Greenhorn

Joined: Dec 22, 2003
Posts: 7
I would like to move the selected row to be the first row in a JTable. I don't want to copy the data into the first row of the model.
I have a class which has as parameters a jtextfield and table.
if I type string in the jtextfield, the class tries to match the string within a column containing string values. Currently it selects the matching row and make it visible. But, I would like to make the matching row visible and be the first visible row in the table.


SCJP,SCWD
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
needs *lots* of testing

S. Osbourne
Greenhorn

Joined: Dec 22, 2003
Posts: 7
Thanks for the response but this does not solve my probem. I have the code working to match the appropriate row in the table to text entered in textfield.
Currently it matches and scrolls to the match row. But, I would like it to scroll to the top most visible row in the table. I want the founded row to be the first row in viewport,it should be highlighted and be the first visible row in table. There could be other rows above the highlighted row. The user could scroll up or down to show the rows below and above the selected row.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
In the demo program, the program opens showing rows 0 to 4
if I enter 25 into the textfield and click the button, row 25 (0-based)
is the top row showing in the viewport (the rows showing are 25 to 29).
if I then enter 3, row 3 is the top row (showing 3 to 7)
if I then enter 47, row 45 is the top row (the scrollbar only goes to 49,
so showing is 45 to 49)

That's how your description reads to me, so I'm not really sure what you are
trying to achieve.

Just working with the 25, what rows do you want to see when 25 is entered?
S. Osbourne
Greenhorn

Joined: Dec 22, 2003
Posts: 7
It works fine, thank you very mouch.
S. Osbourne
Greenhorn

Joined: Dec 22, 2003
Posts: 7
Tried the same technique with a Jlist and was unable to scroll to top of the JList. Any ideas?

Thanks
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try this for the JList

S. Osbourne
Greenhorn

Joined: Dec 22, 2003
Posts: 7
Thank you, it works great.

Thanks very much.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to move the selected row in Jtable to be the first row in the table