SWT(JFace)體驗(yàn)之Slider,Scale
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();
}
}
再看一個(gè)演示:
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();
}
}
相關(guān)文章
Spring Cloud Feign簡(jiǎn)單使用詳解
本篇文章主要介紹了Spring Cloud Feign簡(jiǎn)單使用詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
Java的函數(shù)式接口@FunctionalInterface的使用說(shuō)明
這篇文章主要介紹了Java的函數(shù)式接口@FunctionalInterface的使用說(shuō)明,我們常用的一些接口Callable、Runnable、Comparator等在JDK8中都添加了@FunctionalInterface注解,需要的朋友可以參考下2024-01-01
SWT(JFace)體驗(yàn)之GridLayout布局
GridLayout 布局的功能非常強(qiáng)大,也是筆者常用的一種布局方式。GridLayout是網(wǎng)格式布局,它把父組件分成一個(gè)表格,默認(rèn)情況下每個(gè)子組件占據(jù)一個(gè)單元格的空間,每個(gè)子組件按添加到父組件的順序排列在表格中。2009-06-06
java阿拉伯?dāng)?shù)字轉(zhuǎn)中文數(shù)字
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)阿拉伯?dāng)?shù)字轉(zhuǎn)換為中文數(shù)字,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04
Java攔截器Interceptor實(shí)現(xiàn)原理及代碼示例
本文詳細(xì)講解了Java攔截器Interceptor實(shí)現(xiàn)原理及代碼示例,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12
java利用反射實(shí)現(xiàn)動(dòng)態(tài)代理示例
這篇文章主要介紹了java利用反射實(shí)現(xiàn)動(dòng)態(tài)代理示例,需要的朋友可以參考下2014-04-04
Java利用ElasticSearch實(shí)現(xiàn)自動(dòng)補(bǔ)全功能
這篇文章主要為大家詳細(xì)介紹了Java如何利用ElasticSearch實(shí)現(xiàn)跟谷歌和百度類(lèi)似的下拉補(bǔ)全提示功能,文中的示例代碼講解詳細(xì),需要的可以參考一下2023-08-08
詳解用Spring Boot零配置快速創(chuàng)建web項(xiàng)目
本篇文章主要介紹了詳解用Spring Boot零配置快速創(chuàng)建web項(xiàng)目,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03

