Java/SWT JFace Eclipse/Scale
Create a scale (maximum 40, page increment 5)
/*
* Scale example snippet: create a scale (maximum 40, page increment 5)
*
* For a list of all SWT example snippets see
* http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
*/
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 Snippet45 {
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
Scale scale = new Scale (shell, SWT.BORDER);
scale.setSize (200, 64);
scale.setMaximum (40);
scale.setPageIncrement (5);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}
Scale Example
/******************************************************************************
* All Right Reserved.
* Copyright (c) 1998, 2004 Jackwind Li Guojie
*
* Created on 2004-3-29 13:10:11 by JACK
* $Id$
*
*****************************************************************************/
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();
//textUser.forceFocus();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
}
private void init() {
}
public static void main(String[] args) {
new ScaleExample();
}
}
Scales
/******************************************************************************
* All Right Reserved.
* Copyright (c) 1998, 2004 Jackwind Li Guojie
*
* Created on 2004-3-29 13:32:09 by JACK
* $Id$
*
*****************************************************************************/
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();
//textUser.forceFocus();
// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}
display.dispose();
}
private void init() {
}
public static void main(String[] args) {
new Scales();
}
}