aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Rolling Scrollbar to JScrollPane's top Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Rolling Scrollbar to JScrollPane Watch "Rolling Scrollbar to JScrollPane New topic
Author

Rolling Scrollbar to JScrollPane's top

Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
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

Joined: Sep 28, 2000
Posts: 508
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

Joined: Dec 08, 2001
Posts: 160
Thanks a lot. It worked.
Sri
 
Don't get me started about those stupid light bulbs.
 
subject: Rolling Scrollbar to JScrollPane's top