Java Tutorial/SWT/Slider
Introducing Slider
- Sliders allow users to select a value within a given range.
- You can create both horizontal and vertical sliders(SWT.HORIZONTAL or SWT.VERTICAL ) .
Set Slider Min and Max Value
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Slider;
public class SliderMinMaxValue {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
// Create a horizontal Slider, accepting the defaults
new Slider(shell, SWT.HORIZONTAL);
// Create a vertical Slider and set its properties
Slider slider = new Slider(shell, SWT.VERTICAL);
slider.setMinimum(0);
slider.setMaximum(100);
slider.setIncrement(5);
slider.setPageIncrement(20);
slider.setSelection(75);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}