Java Reference
In-Depth Information
The look and feel, which is established in the setLookAndFeel() method in lines 54-63,
is called at the beginning and end of the frame's constructor method. Because you're
opening several dialog boxes in the constructor, you must set up the look and feel before
opening them.
Sliders
Sliders, which are implemented in Swing with the JSlider class, enable the user to set a
number by sliding a control within the range of a minimum and maximum value. In
many cases, a slider can be used for numeric input instead of a text field, and it has the
advantage of restricting input to a range of acceptable values.
Figure 10.11 shows an example of a JSlider component.
FIGURE 10.11
A JSlider compo-
nent.
10
Sliders are horizontal by default. The orientation can be explicitly set using two class
constants of the SwingConstants interface: HORIZONTAL or VERTICAL .
You can use the following constructor methods:
JSlider( int , int ) —A slider with the specified minimum value and maximum
value
n
JSlider( int , int, int ) —A slider with the specified minimum value, maximum
value, and starting value
n
JSlider( int, int, int, int ) —A slider with the specified orientation, mini-
mum value, maximum value, and starting value
n
Slider components have an optional label that can be used to indicate the minimum
value, maximum value, and two different sets of tick marks ranging between the values.
The default values are a minimum of 0, maximum of 100, starting value of 50, and hori-
zontal orientation.
The elements of this label are established by calling several methods of JSlider :
setMajorTickSpacing( int ) —This method separates major tick marks by the
specified distance. The distance is not in pixels, but in values between the mini-
mum and maximum values represented by the slider.
n
Search WWH ::




Custom Search