This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Swing and JScrollBar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing and JScrollBar " Watch "Swing and JScrollBar " New topic
Author

Swing and JScrollBar

guptabandhu roy
Greenhorn

Joined: Mar 22, 2008
Posts: 9
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

Joined: Oct 13, 2005
Posts: 38036
    
  22
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

Joined: Jun 13, 2009
Posts: 2154
    
    7
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:

 
wood burning stoves
 
subject: Swing and JScrollBar
 
Similar Threads
add ScrollBars To JScrollPane
regarding JTable scrollabrs
Help with JScrollPane
Scrolling a JDesktopPane when JInternalFrames go outside the Standard View
New Image in JScrollPane