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 ?
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.
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: