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 JPanel & 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 "JPanel & JScrollPane" Watch "JPanel & JScrollPane" New topic

JPanel & JScrollPane

S.Subhash Chandran

Joined: Dec 31, 2002
Posts: 27
I have a class which extends JPanel. 2D images are drawn on it dynamically, as are components added to it. The problem is that when an instance of this object is added to the window:
getContentPane().add(new JScrollPane(myPanel));
I don't get the scroll bars when components are added to it dynamically below the viewport. Help!!!

Subhash Chandran S<br /><a href="" target="_blank" rel="nofollow"></a>
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You'll have to modify the preferred size of the component when you add shapes. You'll also need to call parent.validate() to force the scroll pane to redraw...

I think I have an example here.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
It is sorta covered in the JavaRanch Style Guide.
subject: JPanel & JScrollPane
It's not a secret anymore!