This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes scrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "scrollPane " Watch "scrollPane " New topic
Author

scrollPane

Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
I have an empty JPanel inside a ScrollPane. I draw graphics on the JPanel that go out of what can be sean by the scrollPane. Regardless of how big I make the JPanel, I can't scroll the scrollPane to view it.

Question is - why can't I scroll around a blank panel? What do I need to do to be able to do so?

note: The verticalScrollBar is set to Always show. Thanks.
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
What do you mean exactly?

Does it appear that your panel is not resized?

Or perhaps that your scroll bars don't appear?

Something else maybe?
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
Hi Rich

I think you should set the PreferredSize of your empty JPanel to be at least as big as the graphic you drawed is, if you have done so. Then you will see the ScrollBar properly.


Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The JScrollPane will ask your custom (graphic) component for its size so it can figure out how to properly display it. If the component has child components then its layout manager will figure out a preferred size that the component can pass on to the JScrollPane when it calls to collect the information. When you render graphics/images on your component it has no way of knowing the dimensions of the graphics to pass on to the inquiring JScrollPane. So you can use the JComponent method setPreferredSize, as Pat Hays has said, to inform the JScrollPane. You also have the option of overriding getPreferredSize and returning the size requirements for your component.

This is very useful in the AWT where we don't have access to setPreferredSize.
Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
Thanks a lot. Preferred size did it.

I have another odd problem though. When I scroll the panel now ,up or down, the panel's graphics get distorted. I have buttons above the panel(#1) in another panel(#2) and it seems the button graphics from #2 are scrolled on #1 like they were part of #1? if that makes sense.

Anyway I added AdjustmentListener to the vertical scrollbar and simply repaint when there is a change - this fixed that. I thought it was odd , does anyone else know a way around that? Thanks again.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scrollPane
 
Similar Threads
Multiple JTables in a single Scrollpane
JScrollPane problem
GUI Scrollbar and file browser
Adding JScollPane into JPanel
Problem in inserting tree in scrollpane