Slider:
Copy Code code as follows:
Package Swt_jface.demo8;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.layout.GridData;
Import Org.eclipse.swt.layout.GridLayout;
Import Org.eclipse.swt.widgets.Display;
Import org.eclipse.swt.widgets.Event;
Import Org.eclipse.swt.widgets.Label;
Import Org.eclipse.swt.widgets.Listener;
Import Org.eclipse.swt.widgets.Shell;
Import Org.eclipse.swt.widgets.Slider;
Import Org.eclipse.swt.widgets.Text;
public class Sampleslider {
Display display = new display ();
Shell shell = new shell (display);
Slider Slider;
Text value;
Public Sampleslider () {
Shell.setlayout (New GridLayout (1, true));
Label label = new label (Shell, SWT. NULL);
Label.settext ("Volume:");
slider = new Slider (shell, SWT. VERTICAL);
Slider.setbounds (0, 0, 40, 200);
Slider.setmaximum (24);
Slider.setminimum (0);
Slider.setincrement (1);
Slider.setpageincrement (5);
Slider.setthumb (4);
Slider.addlistener (SWT. Selection, New Listener () {
public void Handleevent (event event) {
int perspectivevalue = Slider.getmaximum ()-slider.getselection () + slider.getminimum ()-Slider.getthumb ();
Value.settext ("Vol.:" + Perspectivevalue);
}
});
Value = new Text (Shell, SWT. BORDER | Swt. Single);
Value.seteditable (FALSE);
Slider.setlayoutdata (New Griddata (Griddata.horizontal_align_center));
Value.setlayoutdata (New Griddata (Griddata.horizontal_align_center));
Shell.pack ();
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Sampleslider ();
}
}
Scale:
Copy Code code as follows:
Package Swt_jface.demo8;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Scale;
Import Org.eclipse.swt.widgets.Shell;
public class Scales {
Display display = new display ();
Shell shell = new shell (display);
Public scales () {
Scale Scaleh = new Scale (Shell, SWT. NULL);
Scale Scalev = new Scale (Shell, SWT. VERTICAL);
Scaleh.setbounds (0, 0, 100, 50);
Scalev.setbounds (0, 50, 50, 100);
System.out.println ("Min:" + scaleh.getminimum ());
System.out.println ("Max:" + scaleh.getmaximum ());
Shell.pack ();
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Scales ();
}
}
Package Swt_jface.demo8;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Scale;
Import Org.eclipse.swt.widgets.Shell;
public class Scales {
Display display = new display ();
Shell shell = new shell (display);
Public scales () {
Scale Scaleh = new Scale (Shell, SWT. NULL);
Scale Scalev = new Scale (Shell, SWT. VERTICAL);
Scaleh.setbounds (0, 0, 100, 50);
Scalev.setbounds (0, 50, 50, 100);
System.out.println ("Min:" + scaleh.getminimum ());
System.out.println ("Max:" + scaleh.getmaximum ());
Shell.pack ();
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Scales ();
}
}
Look at one more demo:
Copy Code code as follows:
Package Swt_jface.demo8;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.layout.GridData;
Import Org.eclipse.swt.layout.GridLayout;
Import Org.eclipse.swt.widgets.Display;
Import org.eclipse.swt.widgets.Event;
Import Org.eclipse.swt.widgets.Label;
Import Org.eclipse.swt.widgets.Listener;
Import Org.eclipse.swt.widgets.Scale;
Import Org.eclipse.swt.widgets.Shell;
Import Org.eclipse.swt.widgets.Text;
public class Scaleexample {
Display display = new display ();
Shell shell = new shell (display);
Scale Scale;
Text value;
Public Scaleexample () {
Shell.setlayout (New GridLayout (1, true));
Label label = new label (Shell, SWT. NULL);
Label.settext ("Volume:");
Scale = new scale (shell, SWT. VERTICAL);
Scale.setbounds (0, 0, 40, 200);
Scale.setmaximum (20);
Scale.setminimum (0);
Scale.setincrement (1);
Scale.setpageincrement (5);
Scale.addlistener (SWT. Selection, New Listener () {
public void Handleevent (event event) {
int perspectivevalue = Scale.getmaximum ()-scale.getselection () + scale.getminimum ();
Value.settext ("Vol.:" + Perspectivevalue);
}
});
Value = new Text (Shell, SWT. BORDER | Swt. Single);
Value.seteditable (FALSE);
Scale.setlayoutdata (New Griddata (Griddata.horizontal_align_center));
Value.setlayoutdata (New Griddata (Griddata.horizontal_align_center));
Shell.pack ();
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Scaleexample ();
}
}