SWT制作下拉式ToolBar菜单代码
SWT制作下拉式toolbar菜单按钮的代码片段:final ToolItem dropdown = new ToolItem(bar, SWT.DROP_DOWN);
dropdown.setText("Drop-down");
//一个popoupMenu
final Menu menu = new Menu(shell, SWT.POP_UP);
MenuItem choice = new MenuItem(menu, SWT.PUSH);
choice.setText("Choices");
dropdown.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (event.detail == SWT.ARROW) {
Rectangle rect = dropdown.getBounds();
Point pt = new Point(rect.x, rect.y rect.height);
pt = bar.toDisplay(pt);
menu.setLocation(pt.x, pt.y);
menu.setVisible(true);
}
}
});
页:
[1]