10.2 Class Scale
10.2.1 Example

10.2.2 Scale Hierarchy

10.2.3 Scale Styles
Style | Description |
|---|
SWT.HORIZONTAL | Create a horizontal scale | SWT.VERTICAL | Create a vertical scale |
10.2.4 Scale Events
Event | Description |
|---|
SWT.Selection | The scale was selected |
Scales are user interface elements that allow the user to select from a series of integer values. Scales often draw a small draggable box, called the thumb, which is dragged by the user within a "trough." The trough is surrounded on either side by a succession of short lines called ticks.
Unlike ProgressBar, Scale is not static. The following example code creates a scale in a shell.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Scale scale = new Scale(shell, SWT.HORIZONTAL);
scale.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Scales are often used to implement sliding "volume controls."
10.2.5 Range Operations
Scale provides the following range operations.
setMinimum(int minimum)
Sets the minimum. If this value is negative or greater than or equal to the maximum, the value is ignored. The selection is adjusted to fit within the new range. getMinimum()
Returns the minimum. If this value has never been set, the default value is zero. setMaximum(int maximum)
Sets the maximum. If this value is negative or less than or equal to the minimum, the value is ignored. The selection is adjusted to fit within the new range. getMaximum()
Returns the maximum. If this value has never been set, the default value is 100.
10.2.6 The Selection
The selection within a scale refers to the position of the thumb. Although the thumb takes up space on the screen, it does not affect the range. This means that the selection can vary from the minimum value to the maximum.
setSelection(int value)
Sets the selection. If the selection is out of range, it is adjusted to fit within the range. getSelection()
Returns the selection. The default is zero.
10.2.7 Increment and Page Increment
Scale provides API that allows you to set the increment and page increment. These are the values the scale uses to increment the selection when the user drags the thumb or clicks inside the trough. The user can also manipulate the thumb using the keyboard. In this case, typically the arrow keys move the thumb using the increment, and the <Page Up> and <Page Down> keys move it using the page increment.
Setting the increment and page increment does not affect the minimum, maximum, and selection. The following methods are used to set the two kinds of increment.
setIncrement(int increment)
Sets the increment value. If this value is less than or equal to zero, the value is ignored. getIncrement()
Returns the increment. If this value has never been set, the default value is 1. setPageIncrement(int pageIncrement)
Sets the page increment value. If this value is less than or equal to zero, the value is ignored. getPageIncrement()
Returns the page increment. If this value has never been set, the default value is 1.
10.2.8 Scale Events
SWT.Selection (SelectionEvent)
The SWT.Selection event (typed event SelectionEvent) is sent whenever the user changes the scale using the mouse or the keyboard. Selection events contain meaningful values in only the display, widget, and type fields.
|