This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable positioning row at top  RSS feed

 
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
 
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
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!