File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to get JScrollPane to go to top left?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to get JScrollPane to go to top left??" Watch "How to get JScrollPane to go to top left??" New topic
Author

How to get JScrollPane to go to top left??

Lee Barney
Ranch Hand

Joined: May 07, 2003
Posts: 37
I have a series of JPanels that are embeded in a single JPanel that resides in a JScrollPane.
Each time I call show() on the JInternalFrame within which this all resides it ends up displaying the top in a flash and then scrolls to the bottom. I need the display to remain at the top of the JScrollPane.
I have tried several things both before and after calling JInternalFrame show() all to no avail.
Any ideas would be greatly appreciated.
Example of tried code:
mainScrollPane.scrollRectToVisible(new Rectangle(0,0,20,50));
Jon Dornback
Ranch Hand

Joined: Apr 24, 2002
Posts: 137
use the getVerticalScrollBar() and getHorizontalScrollBar() methods of JScrollPane, and then call setValue on them.
example:


use the [CODE] tags - it makes it much easier for people to help you.
Lee Barney
Ranch Hand

Joined: May 07, 2003
Posts: 37
I added your code in and put a print statement prior to and after the call to show. Both indicate that the position of the vertical scroll is zero and yet the scroll bar is at the bottom of the panel.
Very confusing to me. I have gone back again to make sure that I am using the correct panel and have verified that I am.
Any ideas?
Thanks
Jon Dornback
Ranch Hand

Joined: Apr 24, 2002
Posts: 137
I have used that method in a couple apps, and seems to work fine for me. if you have some sample code, i'll take a look at it if you post it here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get JScrollPane to go to top left??