In the past, we thought that slider and scale are only the differences in appearance. Today we found that this is not the case, because slider has a feature: getselection () can get the most
The iterator is not the value of getmaximum (). It must be subtracted from the getthumb () value. The latter is the value of the middle slider. The default value is 10 and the minimum value is 1. Run thisProgramObserve
Output.
Import Org. Eclipse. SWT. * ;
Import Org. Eclipse. SWT. Events. selectionadapter;
Import Org. Eclipse. SWT. Events. selectionevent;
Import Org. Eclipse. SWT. widgets. * ;
Public ClassSlidertest {
Public Static Void Main (string [] ARGs ){
Display display = New Display ();
Shell = New Shell (Display );
// Slider
Final Slider = New Slider (shell, SWT. Horizontal );
Slider. setbounds ( 10 , 10 , 200 , 32 );
Slider. setminimum ( 0 );
Slider. setmaximum ( 100 );
Slider. setthumb ( 5 );
Slider. addselectionlistener ( New Selectionadapter (){
Public Void Widgetselected (selectionevent e ){
System. Out. println ( " Slider selection: " + Slider. getselection ());
}
});
// Scale
Final Scale = New Scale (shell, SWT. Horizontal );
Scale. setbounds ( 10 , 50 , 200 , 72 );
Scale. setminimum ( 0 );
Scale. setmaximum ( 100 );
Scale. addselectionlistener ( New Selectionadapter (){
Public Void Widgetselected (selectionevent e ){
System. Out. println ( " Scale selection: " + Scale. getselection ());
}
});
shell. open ();
while ( ! shell. isdisposed () {
If ( ! display. readanddispatch ()
display. sleep ();
}< br> display. dispose ();
}< BR >}