-
Notifications
You must be signed in to change notification settings - Fork 5
Sash Tutorial
Sash是一个可拖动的组件,也有水平的(SWT.HORIZONTAL)和垂直的(SWT.VERTICAL)两种类型。不过我们经常会用到另外一个基于Sash的组件SashForm。
我们还是先通过一个示例来认识一下它吧:
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Sash Tutorial");
shell.setSize(315, 200);
shell.setLayout(new FillLayout(SWT.VERTICAL));
// SWT.HORIZONTAL | SWT.SMOOTH
Group group1 = new Group(shell, SWT.NONE);
group1.setText("Horizontal && Smooth");
Sash hSash = new Sash(group1, SWT.HORIZONTAL | SWT.SMOOTH);
Rectangle rect = group1.getClientArea();
hSash.setBounds(rect.x, 40, 315, 10);
hSash.setBackground(display.getSystemColor(SWT.COLOR_RED));
// SWT.VERTICAL
Group group2 = new Group(shell, SWT.NONE);
group2.setText("Vertical");
final Sash vSash = new Sash(group2, SWT.VERTICAL);
Rectangle r = group2.getClientArea();
vSash.setBounds(150, r.y, 20, 100);
vSash.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
vSash.setBounds(e.x, e.y, e.width, e.height);
}
});
vSash.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
我们来看图:

图中所示的红色横条和灰色竖条就是Sash,他们是可以拖动的。
Sash被设置了SWT.SMOOTH属性之后,Sash的实际位置会随着Sash的拖动而自动更新。反之,Sash不会被真正的拖动,只会出现一个预览,Sash的位置需要自行去修改,请看上面示例中的垂直的Sash。
参考资料:
上一篇:Menu Tutorial 下一篇:ToolTip 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)