Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with JScrollPane

 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the preferred size of the DrawingArea?
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paint has some unnecessary imports. i have been busy refactoring
 
Tony Docherty
Bartender
Posts: 2936
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic