You
can define a scale widget using Scale class.
Following
statements define horizontal scale.
Scale
horizontalScale = new Scale(shell, SWT.HORIZONTAL);
horizontalScale.setMaximum(100);
horizontalScale.setMinimum(10);
horizontalScale.setBounds(50,
50, horizontalScaleWidth, horizontalScaleHeight);
horizontalScale.setPageIncrement(20);
horizontalScale.setBackground(new
Color(display, 255, 255, 255));
Following
statements define vertical scale.
Scale
verticalScale = new Scale(shell, SWT.VERTICAL);
verticalScale.setMaximum(1000);
verticalScale.setMinimum(500);
verticalScale.setBounds(250,
150, verticalScaleWidth, verticalScaleHeight);
verticalScale.setPageIncrement(20);
verticalScale.setBackground(new
Color(display, 255, 255, 255));
Following
is the complete working application.
package swt_app; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Scale; import org.eclipse.swt.widgets.Shell; public class Test { private static int shellWidth = 1000; private static int shellHeight = 700; private static int horizontalScaleWidth = 600; private static int horizontalScaleHeight = 50; private static int verticalScaleWidth = 50; private static int verticalScaleHeight = 400; private static void addWidgetsToShell(Display display, Shell shell) { Scale horizontalScale = new Scale(shell, SWT.HORIZONTAL); horizontalScale.setMaximum(100); horizontalScale.setMinimum(10); horizontalScale.setBounds(50, 50, horizontalScaleWidth, horizontalScaleHeight); horizontalScale.setPageIncrement(20); horizontalScale.setBackground(new Color(display, 255, 255, 255)); Scale verticalScale = new Scale(shell, SWT.VERTICAL); verticalScale.setMaximum(1000); verticalScale.setMinimum(500); verticalScale.setBounds(250, 150, verticalScaleWidth, verticalScaleHeight); verticalScale.setPageIncrement(20); verticalScale.setBackground(new Color(display, 255, 255, 255)); } public static void main(String[] args) { /* Instantiate Display object, it represents SWT session */ Display display = new Display(); /* * Define Shell, it represent a window, You can add more than one shell * to Display */ Shell shell = new Shell(display); shell.setSize(shellWidth, shellHeight); addWidgetsToShell(display, shell); /* Open shell window */ shell.open(); /* * Run the event dispatching loop until an exit condition occurs, which * is typically when the main shell window is closed by the user. */ while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } /* Dispose the display */ display.dispose(); } }
No comments:
Post a Comment