aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JScrollPane adding JPanels at the top and keeping current scroll view Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollPane adding JPanels at the top and keeping current scroll view" Watch "JScrollPane adding JPanels at the top and keeping current scroll view" New topic
Author

JScrollPane adding JPanels at the top and keeping current scroll view

John Jacobs
Greenhorn

Joined: Feb 27, 2011
Posts: 2
I have a JScrollPane that contains a vertical Box. I'm inserting new JPanel's at the top of Box. If I use the scrollbar to scroll down I'd like for the current view to remain where I scrolled down to. For example, if I have 50 panels in the box and use the scrollbar to view panel 20, I'd like the view to remain on box 20 even though other boxes are added on top. Additionally, if I use the scrollbar to scroll back up to the top I'd like the view to display new panels as they are added. Any idea how to do this?

BTW, it isn't necessary to use a JScrollPane or a Box. The example code is just to help explain what I am trying to do.

Example code:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Welcome to the Ranch!

I'll move this thread to our GUI forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
Cross posted: http://stackoverflow.com/questions/5132802/jscrollpane-adding-jpanels-at-the-top-and-keeping-current-scroll-view/5134255#5134255

Be Forthright When Cross Posting To Other Sites
John Jacobs
Greenhorn

Joined: Feb 27, 2011
Posts: 2

Sorry, I forgot. Anyways, the folks at that site where able to provide the solution. Pretty obvious and simple in hindsight.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JScrollPane adding JPanels at the top and keeping current scroll view