• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

scrollPane

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic