aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Changing component inside a JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Changing component inside a JScrollPane" Watch "Changing component inside a JScrollPane" New topic
Author

Changing component inside a JScrollPane

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi, I have a JScrollPane with the Horizontal ScrollBar set to come on as needed.

I want to be able to remove the component (JPanel) added to scrollpane, and then add a different one (say a larger one),
and have the scrollbar update itself so I can then view all of the new component, but I'm not sure how to do it other than perhaps just rebuilding a new ScrollPane, and I guess I'll have to add this into the JPanel its in again too.

Any thoughts? Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

JScrollPane.setViewportView for changing the component, then call revalidate() and repaint() to enforce that the scroll bars are reset correctly.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Thanks, I got it to work using:



I'm not sure if thats what you meant.

It also appears to work using either of setViewPortView or revalidate, so I'm not sure.
I guess I'll stick with what I've got above.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

That's exactly what I meant. revalidate() and repaint() may not be needed, but sometimes you do need them when you modify your user interface at runtime so I always add them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing component inside a JScrollPane