In this section, you will study how to create scale.
In order to create the scale, SWT provides the class Scale of package org.eclipse.swt.widgets.*. This class shows the different ranges of numeric values. The class Label allows to display the text. The class GridData sets the layout of the scale.
The class Text provides the textbox and allows to enter the text. The method setText() set the content to the specified string. The method setEditable(true) sets the editable state to modify the text.
The SWT.HORIZONTAL creates the horizontal scale. The method setMaximum() sets the maximum value of scale and setMinimum() sets the minimum value. The method setIncrement() sets the increment value. The method setPageIncrement() sets the page increment. The method getMinimum() returns the minimum value and getMaximum() returns the maximum value. The method getSelection() returns the selected value. The method addListener() calls the Event class to display the selected value from the scale to the textbox.
Following code displays the selected value:
| int value = scale.getMaximum() - scale.getSelection() + scale.getMinimum(); System.out.println("Speed: " + value); text.setText("Speed: " + value); } |
Here is the code of ScaleExample.java
import org.eclipse.swt.SWT;
|
Output will be displayed as:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Create Scale in SWT
Post your Comment