2

我的工具栏中的两个下拉菜单出现视觉故障。当我:

  1. 将鼠标指针滚动到File下拉菜单按钮上...

    在此处输入图像描述

  2. 滚动到Options下拉菜单按钮...

    在此处输入图像描述

  3. 完全滚出工具栏...

    在此处输入图像描述

文件下拉按钮仍然突出显示,尽管它似乎没有成为焦点。Options如果您从 滚动到File,然后离开工具栏,选项下拉菜单也会发生这种情况。

这是创建ToolBar和的代码ToolItems

final ToolBar toolBar = new ToolBar (mainshell, SWT.DROP_DOWN);
toolBar.setSize(200,35);
toolBar.setLocation(0,0);
    
ToolItem File = new ToolItem(toolBar, SWT.DROP_DOWN);
File.setText("File");
final Menu FdropMenu = new Menu(mainshell, SWT.POP_UP);
File.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent e1) {
        if (e1.detail == SWT.ARROW) {
            final ToolItem FtoolItem = (ToolItem) e1.widget;
            final ToolBar  FtoolBar = FtoolItem.getParent();
            Point point = FtoolBar.toDisplay(new Point(e1.x, e1.y));
            FdropMenu.setLocation(point.x, point.y);
            FdropMenu.setVisible(true);
        } 
    }
}); 
     
final MenuItem SaveMI = new MenuItem(FdropMenu, SWT.PUSH);
final MenuItem OpenMI = new MenuItem(FdropMenu, SWT.PUSH);
 
ToolItem itemDrop = new ToolItem(toolBar, SWT.DROP_DOWN);
itemDrop.setText("Options");
final Menu dropMenu = new Menu(mainshell, SWT.POP_UP);
itemDrop.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent e) {
        if (e.detail == SWT.ARROW) {
            final ToolItem toolItem = (ToolItem) e.widget;
            final ToolBar  toolBar = toolItem.getParent();
            Point point = toolBar.toDisplay(new Point(e.x, e.y));
            dropMenu.setLocation(point.x, point.y);
            dropMenu.setVisible(true);
        } 
    }
}); 

我不确定这是我的编程错误还是 SWT 中的错误。任何支持将不胜感激。

4

1 回答 1

1

我有同样的问题。我发现如果我SWT.FLAT在构造函数中使用样式参数,ToolBar这个问题就会消失。在您的代码中使用此构造函数:

ToolBar toolBar = new ToolBar( parent, SWT.FLAT );
于 2016-10-02T18:10:42.427 回答