时间:2021-05-20
Slider:
复制代码 代码如下:
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:
复制代码 代码如下:
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();
}
}
再看一个演示:
复制代码 代码如下:
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();
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
演示代码:复制代码代码如下:packageswt_jface.demo9;importorg.eclipse.swt.SWT;importorg.eclipse
测试代码如下:复制代码代码如下:packageswt_jface.demo2;importorg.eclipse.swt.SWT;importorg.eclip
代码如下复制代码代码如下:packageswt_jface.demo;importorg.eclipse.swt.SWT;importorg.eclipse.s
演示代码如下:复制代码代码如下:packageswt_jface.demo11;importorg.eclipse.swt.SWT;importorg.ecli
代码如下:复制代码代码如下:packageswt_jface.demo9;importorg.eclipse.swt.SWT;importorg.eclipse