Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing and JScrollBar  RSS feed

 
guptabandhu roy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Guys ,
Merry Christmas and Happy New Year to all of you .
Just had a few questions regarding getting the scrollbars in JScrollPane
1> What is the difference between setSize() and setPreferredSize()
2> If I need to get the scrollbars in JScrollPane do I need to set the size or preferred size of the component it contains to bigger than the JScrollPAne or the parent component of the JScrollPane ? Let me explain with an example :-

JFrame contains JScrollPane contains JDesktopPane . Now lets say I want to see the scrollbars on JScrollPane . What do I need to do ?
How big should I make the JDesktopPane ?
3> Can I detect any sort of action using a ActionListener . If so what is the need for other classes like MouseLIstener ?

Thanks in advance
 
Campbell Ritchie
Sheriff
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you find out when you read the API documentation and the Java™ Tutorial?
Did you read the lists of methods in MouseListener, ActionListener, etc? Or which listeners are available in the Java™ Tutorials?

Remember an action means a button being pressed or similar; this is a "high-level" event, which you are doubtless familiar with from using web browsers, word processors, etc. Moving a mouse is a "low-level" event which you may wish to ignore. As a simple rule of thumb, it is usually better to use the highest-level event available to fulfil your requirements.
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scrollbars appear automatically when the "preferred size" of the component added to the viewport of the scrollpane is greater than the size of the scrollpane. So somewhere you need to determine the preferred size of your desktop pane and then use:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!