To show a custom area for toolbar.
public void postWindowOpen() {
//...
}
//Add to postWindowOpen()
final IWorkbenchWindow window = getWindowConfigurer().getWindow();
Listener listener = new Listener() {
private Shell toolbar;
public void handleEvent(Event event) {
Control control = (Control) event.widget;
Point mouse = control.toDisplay(event.x, event.y);
final Shell shell = window.getShell();
Point location = shell.getLocation();
Point size = shell.getSize();
int xIndent = 2;
int yIndent = 24;
int height = 30;
if (mouse.x > location.x
&& mouse.y > location.y + yIndent
&& location.x + size.x > mouse.x
&& location.y + yIndent + height > mouse.y) {
if (toolbar == null) {
toolbar = new Shell(shell, SWT.NO_TRIM);
toolbar.setSize(size.x - 2 * xIndent, height);
toolbar.setLocation(location.x + xIndent, location.y + yIndent);
GridLayout layout = new GridLayout(24, false);
layout.marginLeft = 0;
layout.marginTop = 0;
toolbar.setLayout(layout);
new Button(toolbar, SWT.PUSH).setText("action 1");
new Button(toolbar, SWT.PUSH).setText("action 2");
new Button(toolbar, SWT.PUSH).setText("action 3");
toolbar.setVisible(true);
}
} else {
if (toolbar != null) {
toolbar.dispose();
toolbar = null;
}
}
}
};
window.getShell().getDisplay().addFilter(SWT.MouseMove, listener);
自定义工具栏显示
本文介绍了一种在窗口中根据鼠标位置动态显示和隐藏自定义工具栏的方法。通过监听鼠标移动事件并判断鼠标位置来决定工具栏的显示与否,同时实现了工具栏的布局和按钮设置。

被折叠的 条评论
为什么被折叠?



