3

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.

Community
  • 1
  • 1
James Allison
  • 135
  • 10
  • 1
    Please post links of the images you mention. We can embed them if necessary. – Zong Nov 29 '13 at 20:25
  • Here are the links I was given when I uploaded the files. I could not post them directly on the article because of the two link limit.http://i.stack.imgur.com/2aRoC.png, http://i.stack.imgur.com/wHEPz.png, http://i.stack.imgur.com/br8q4.png – James Allison Nov 29 '13 at 20:33
  • @JayCodeBuilder Are you sure it's not just a focus issue, i.e. the file menu item having the focus? – Baz Nov 29 '13 at 20:34
  • @Baz I don't think so, I am testing that right now. – James Allison Nov 29 '13 at 20:35
  • @Baz MenuItems in SWT cannot have focus and scrolling over the toolbar does not give it focus. – James Allison Nov 29 '13 at 20:53
  • 1
    @JayCodeBuilder They can have focus, it has focus when I start the application (on Linux) and the focus moves when I press tab. – Baz Nov 29 '13 at 20:57
  • @Baz, maybe you are right, but I cannot set them to focused or add a focus listener to them in the code, I will keep experimenting though. – James Allison Nov 29 '13 at 21:08
  • did you resolve this? because i'm having exactly the same problem – l.moretto Sep 16 '14 at 13:33
  • @l.moretto Unfortunately, no. I was unable to solve this issue. – James Allison Sep 18 '14 at 17:47

1 Answers1

2

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 );
Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
J. Manuel
  • 61
  • 7