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 problem with JScrollPane 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 "problem with JScrollPane" Watch "problem with JScrollPane" New topic

problem with JScrollPane

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340

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

Visit my download page
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

What's the preferred size of the DrawingArea?

How To Ask Questions How To Answer Questions
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340

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 fixed for problem when frame is maximized

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340

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

Joined: Aug 07, 2007
Posts: 2166
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:

For horizintal axis:

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340

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

Joined: May 03, 2008
Posts: 4523

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.
I agree. Here's the link:
subject: problem with JScrollPane
Similar Threads
slight problem using JScrollPane
what would you change if this was your program?
composition vs inheritance
strange problem
File Chooser Dialog box