SWT(JFace)体验之Slider,Scale
时间:2020-12-23 11:53:45|栏目:JAVA代码|点击: 次
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();
}
}
复制代码 代码如下:
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();
}
}
上一篇:Java 并发编程学习笔记之Synchronized底层优化
栏 目:JAVA代码
下一篇:java哈夫曼树实例代码
本文标题:SWT(JFace)体验之Slider,Scale
本文地址:http://www.codeinn.net/misctech/35705.html
阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机