Slider,scale_java Programming of SWT (JFace) Experience

Source: Internet
Author: User
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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.