• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
needs *lots* of testing

 
S. Osbourne
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works fine, thank you very mouch.
 
S. Osbourne
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tried the same technique with a Jlist and was unable to scroll to top of the JList. Any ideas?

Thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this for the JList

 
S. Osbourne
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, it works great.

Thanks very much.
reply
    Bookmark Topic Watch Topic
  • New Topic