Chapter 16. SWT Slider and ProgressBar
Two useful interface elements are sliders and progress bars. Sliders permit the user to choose a value from within a range of values, simply by dragging the control with the mouse. The volume control found in many sound-enabled applications is an example of a slider.
Progress bars are useful when the user has initiated a long-running process such as a file transfer. The progress meter gives the user the ability to monitor the progress of the operation, to see how much of the operation is complete as well as how much remains.
The SWT provides the classes needed to easily include both sliders and progress bars in your applications.
The SWT Slider Class
The ability to create
sliders in the SWT is encapsulated in a
Slider, part of the
Slider provides the ability to use a single widget
to enable the user to specify a range of values, much like was done
Button in Chapter 6. In
fact, building a similar interface using
a great way to examine the uses of the
How do I do that?
To duplicate the
SWT.ARROW Button example from
Chapter 6, you must create a
Shell and add two widgets—a
Text to display the data and a
Slider to enable the user to alter the data. Example 16-1 demonstrates how to do this.
Example 16-1. Using a Slider to obtain input
import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; ...