SWT drop down menu button visual glitch

775 views Asked by At

I am having trouble with a visual glitch on my two drop down menus in my toolbar. When I:

  1. Scroll my mouse pointer over the File drop down menu button...

    enter image description here

  2. Scroll across to the Options drop down menu button...

    enter image description here

  3. Scroll off the toolbar entirely...

    enter image description here

The File dropdown button remains highlighted, although, it doen't seem to be in focus. This happens to the Options drop down menu as well if you scroll from the Options to the File and then off the toolbar.

Here is the code that creates the ToolBar and 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);
        } 
    }
}); 

I am not sure if this is an error in my programming or a bug in SWT. Any support would be appreciated.

1

There are 1 answers

0
J. Manuel On

I had the same problem. I've discovered that if I use the SWT.FLAT style parameter in the ToolBar constructor this problem disappears. Use this constructor in your code:

ToolBar toolBar = new ToolBar( parent, SWT.FLAT );