Slider:
CopyCode The Code is 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 ){
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 codeThe Code is 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, and 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, and 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 ();
}
}
Let's look at another demonstration:
Copy code The Code is 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 ){
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 ();
}
}