![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e794. Creating a JSlider Component// Create a horizontal slider with min=0, max=100, value=50 JSlider slider = new JSlider(); // Create a horizontal slider with custom min and max; value is set to the middle int minimum = -255; int maximum = 256; slider = new JSlider(minimum, maximum); // Create a horizontal slider with custom min, max, and value int initValue = 0; slider = new JSlider(minimum, maximum, initValue); // Create a vertical slider with min=0, max=100, value=50 slider = new JSlider(JSlider.VERTICAL); // Create a vertical slider with custom min, max, and value slider = new JSlider(JSlider.VERTICAL, minimum, maximum, initValue);In addition to allowing the user to drag the slider, some look and feels allow the user page the slider by a fixed amount. This amount is called the extent. // Set an extent int extent = 10; slider.setExtent(extent);For most look and feels, the slider appears as a knob on a track. In this case, it is possible to hide the track: slider.setPaintTrack(false);
e796. Setting the Orientation of a JSlider Component e797. Showing Tick Marks on a JSlider Component e798. Showing Tick-Mark Labels on a JSlider Component e799. Constraining JSlider Component Values to Tick Marks e800. Listening for Value Changes in a JSlider Component © 2002 Addison-Wesley. |