I am having trouble with a visual glitch on my two drop down menus in my toolbar. When I:
Scroll my mouse pointer over the
File
drop down menu button...Scroll across to the
Options
drop down menu button...Scroll off the toolbar entirely...
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.
I had the same problem. I've discovered that if I use the
SWT.FLAT
style parameter in theToolBar
constructor this problem disappears. Use this constructor in your code: