Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get JScrollPane to go to top left??

 
Lee Barney
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the getVerticalScrollBar() and getHorizontalScrollBar() methods of JScrollPane, and then call setValue on them.
example:
 
Lee Barney
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic