Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable positioning row at top

 
Graham Mead
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm trying to develop a JTable so that I can position a specific row at the TOP of the JTable.
I've seen examples using scrollRectToVisible() but this just makes the row visible but if the row is below the viewport it puts the row at the bottom not the top.
If the row is above the viewport then it works ok.
I've got it to work by issuing the scrollRectToVisible() method twice. Once with a v large row number then the actual one to force the row above the viewport on the first call. This seems very clunky/inefficient though!
Does anyone have any ideas.
As an extension to this I also want to position a row to the top even if the view is large enough to display all the rows, hence no scrollbar.
TIA Graham
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Graham,
Why not do it with the table model? Whatever row it is you want displayed at the top, could be returned in the getValueAt method of the table model. You would of course have to keep up with that row in the model.
Hope this helps,
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic