Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rolling Scrollbar to JScrollPane's top

 
Sri Rangan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have MAIN JPanel which have many panels added to it. When I add the MAIN JPanel to the JScrollPane, the Scrollbar will have to appear at the top. I tried

It is not working. The Scrollbar appearing at end of the last jPanel added to the Main Panel.
Thanks for your help
Sri
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one possibility is: put all components you have added now to the JScrollPane directly into a JPanel and add this single JPanel to the JScrollPane as viewport.
another solution is, to add all the components to the viewport, after creating the viewport explicitely.
I don't think calling scrollPane.add() is a good idea. these methods are inherited from container and aren't modified by JScrollPane. (my opinion!)
if you want to stick with your code, try:
scrollPane.getVerticalScrollBar().setValue(0);
 
Sri Rangan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. It worked.
Sri
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic