Java SWT Scale Tutorial with Examples
1. SWT Scale
SWT Scale is interface component which allows the user to select a numeric value in a set of continuous ones.
Below is 2 Scales including the vertical scale and the horizontal one.
SWT Scale contains ticks marking its continuous value. These ticks are equally spaced.
2. SWT Scale Example
ScaleDemo.java
package org.o7planning.swt.scale;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
public class ScaleDemo {
public ScaleDemo() {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("SWT Scale (o7planning.org)");
shell.setSize(400, 270);
shell.setLayout(new GridLayout(1, true));
Label label = new Label(shell, SWT.NULL);
label.setText("Brightness:");
// Scale
Scale scale = new Scale(shell, SWT.VERTICAL);
scale.setMaximum(100);
scale.setMinimum(0);
scale.setIncrement(1);
scale.setPageIncrement(5);
// Info
Label labelInfo = new Label(shell, SWT.NONE | SWT.CENTER);
GridData gd = new GridData(40, SWT.DEFAULT);
labelInfo.setLayoutData(gd);
// Event
scale.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int value = scale.getMaximum() - scale.getSelection() + scale.getMinimum();
labelInfo.setText("" + value);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new ScaleDemo();
}
}
Java SWT Tutorials
- Java SWT FillLayout Tutorial with Examples
- Java SWT RowLayout Tutorial with Examples
- Java SWT SashForm Tutorial with Examples
- Java SWT Label Tutorial with Examples
- Java SWT Button Tutorial with Examples
- Java SWT Toggle Button Tutorial with Examples
- Java SWT Radio Button Tutorial with Examples
- Java SWT Text Tutorial with Examples
- Java SWT Password Field Tutorial with Examples
- Java SWT Link Tutorial with Examples
- Programming Java Desktop Application Using SWT
- Java SWT Combo Tutorial with Examples
- Java SWT Spinner Tutorial with Examples
- Java SWT Slider Tutorial with Examples
- Java SWT Scale Tutorial with Examples
- Java SWT ProgressBar Tutorial with Examples
- Java SWT TabFolder and CTabFolder Tutorial with Examples
- Java SWT List Tutorial with Examples
Show More