June 2013
Beginner
1007 pages
33h 32m
English
JScrollPane is such a
handy component that you may not ever need to use scrollbars by
themselves. In fact, if you ever do find yourself using a scrollbar by
itself, chances are that you really want to use another component called a
slider.
There’s not much point in describing the appearance and functionality of scrollbars and sliders. Instead, let’s jump right in with an example that includes both components. Figure 17-12 shows a simple example with both a scrollbar and a slider.

Figure 17-12. Using a scrollbar and a slider
Here is the source code for this example:
//file: Slippery.javaimportjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;publicclassSlippery{publicstaticvoidmain(String[]args){JFrameframe=newJFrame("Slippery v1.0");Containercontent=frame.getContentPane();// unnecessary in 5.0+JPanelmain=newJPanel(newGridLayout(2,1));JPanelscrollBarPanel=newJPanel();finalJScrollBarscrollBar=newJScrollBar(JScrollBar.HORIZONTAL,0,48,0,255);intheight=scrollBar.getPreferredSize().height;scrollBar.setPreferredSize(newDimension(175,height));scrollBarPanel.add(scrollBar);main.add(scrollBarPanel);JPanelsliderPanel=newJPanel();finalJSliderslider=newJSlider(JSlider.HORIZONTAL,0,255,128);slider.setMajorTickSpacing(48);slider.setMinorTickSpacing(16);slider.setPaintTicks ...