-
Notifications
You must be signed in to change notification settings - Fork 5
Scale Tutorial
Jin Liu edited this page Mar 24, 2015
·
6 revisions
刻度条(Scale)比较简单,分为水平的(SWT.HORIZONTAL)和垂直的(SWT.VERTICAL)两种。
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Scale Tutorial");
shell.setSize(300, 200);
shell.setLayout(new RowLayout(SWT.VERTICAL));
Scale vScale = new Scale(shell, SWT.VERTICAL);
Scale hScale = new Scale(shell, SWT.HORIZONTAL);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
如图:

-
Minimum Value:
设置最小刻度值,最小是0。 -
Maximum Value:
设置最大刻度值,必须比最小值刻度值大。 -
Page Increment:
设置刻度一格的大小,最小值是1。 -
Increment:
设置用键盘上下或左右方向键滚动时的值,最小为1。通常情况下,上下方向键对垂直的刻度条有效,左右方向键对水平的刻度条有用。 -
Selection:
设置当前滚动条的位置,最小为0。
1. Selection:通过addSelectionListener(SelectionListener)或addListener(SWT.Selection, Listener)添加。
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Scale Tutorial");
shell.setSize(300, 200);
shell.setLayout(new GridLayout());
final Label label = new Label(shell, SWT.NONE);
label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Scale scale = new Scale(shell, SWT.HORIZONTAL);
scale.setMaximum(100);
scale.setPageIncrement(10);
scale.setIncrement(5);
scale.setSelection(20);
scale.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
label.setText("Selection: " + scale.getSelection());
}
});
scale.setFocus();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
参考资料:
- Scale snippets
- 如果想了解更多的关于设置颜色,字体等其它属性的相关内容,请移步至控件的通用设置。
- 如果想了解更多的关于
Layout和LayoutData的相关内容,请移步至布局管理器。 - SWT Example: ControlExample
- Sample code and further information
上一篇:Combo Tutorial 下一篇:Slider Tutorial
Soyatec Eclipse Plug-in and RCP Tutorials, wrote by Jin Liu (jin.liu@soyatec.com).
Eclipse Plug-in Development Tutorial
-
Standard Widget Toolkit Tutorial
-
Widgets Tutorial
- Label Tutorial
- Button Tutorial
- Text Tutorial
- Combo Tutorial
- List Tutorial
- Scale Tutorial
- Slider Tutorial
- Spinner Tutorial
- DateTime Tutorial
- Table Tutorial
- Tree Tutorial
- ToolBar Tutorial
- CoolBar Tutorial
- ProgressBar Tutorial
- ScrollBar Tutorial
- TaskBar Tutorial
- ExpandBar Tutorial
- Menu Tutorial
- Sash Tutorial
- ToolTip Tutorial
- Tray Tutorial
- Link Tutorial
- Browser Tutorial
- Dialog Tutorial
- Common Properties Tutorial
- Components Tutorial
- Shell Tutorial
- Display Tutorial
- SWT Custom Widgets Tutorial
- Drag and Drop Tutorial
- Layouts Tutorial
- Resource Management Tutorial
-
Widgets Tutorial
-
[JFace Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/JFace-Tutorial)
- [JFace Viewers Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/JFace-Viewers-Tutorial)
- [TableViewer Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/TableViewer-Tutorial)
- [TreeViewer Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/TreeViewer-Tutorial)
- [ListViewer Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/ListViewer-Tutorial)
- [ComboViewer Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/ComboViewer-Tutorial)
- [JFace Dialogs Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/JFace-Dialogs-Tutorial)
- [JFace DataBinding Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/JFace-DataBinding-Tutorial)
- [JFace Viewers Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/JFace-Viewers-Tutorial)
-
[Plug-in Development Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Plug-in-Development-Tutorial)
- [Views Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Views-Tutorial)
- [Editors Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Editors-Tutorial)
- [Action and Menus Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Action-and-Menus-Tutorial)
- [Preferences Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Preferences-Tutorial)
- [ExtensionPoint Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/ExtensionPoint-Tutorial)
- [Publish Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Publish-Tutorial)
- [Feature Project Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Feature-Project-Tutorial)
- [UpdateSite Project Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/UpdateSite-Project-Tutorial)
- [Fragment Project Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Fragment-Project-Tutorial)
-
[Eclipse 3.x RCP Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Eclipse-3.x-RCP-Tutorial)
- [Branding Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Branding-Tutorial)
- [Publish RCP Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/Publish-RCP-Tutorial)
-
[Graphical Editing Framework Tutorial] (https://github.com/ecsoya/eclipse.tutorial/wiki/GEF-Tutorial)