aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problem with JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem with JScrollPane" Watch "problem with JScrollPane" New topic
Author

problem with JScrollPane

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

i have two apps. one called ImageViewer has scrollbars. the other i am trying to add them. with ImageViewer it was simple

similar code for the other program doesn't display the scrollbars

DrawingArea extends JPanel


SCJP
Visit my download page
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

What's the preferred size of the DrawingArea?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

from what i can gather, that is the problem. it apparently wasn't a problem for the JLabel though. i will list more code.
ImageViewer

ImageViewer fixed for problem when frame is maximized

Paint
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

Paint has some unnecessary imports. i have been busy refactoring
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2317
    
  49
If you want to control the scroll bars visibility then use one of the JScrollPane constructors that always you to set the scroll bar policy for each axis to one of the following (default is XXX_AS_NEEDED):

For vertical axis:
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS

For horizintal axis:
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

as you say, AS_NEEDED is what i want. i just have to figure out this preferred size issue it looks like.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

I would override getPreferredSize() to compute and return an appropriate Dimension. If the computation is expensive, and doesn't change, I would do it at construction and store the value in a field.

Depending on the layout manager used and the factors that determine the preferred size, it may be prudent to also override getMinimum/MaximumSize().


luck, db
There are no new questions, but there may be new answers.
 
 
subject: problem with JScrollPane