File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Rolling Scrollbar to JScrollPane Watch "Rolling Scrollbar to JScrollPane New topic

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
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:
Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Thanks a lot. It worked.
subject: Rolling Scrollbar to JScrollPane's top
Similar Threads
ScrollPane trouble
A few GUI questions
Wants Header of a JTable to be static.
jpanel help
JScrollPane adding JPanels at the top and keeping current scroll view