Community
Participate
Working Groups
I20110124-1800 1. Run the snippet. You will get one focus print statement. 2. Hit 'Space' to create the popup. 3. Try Alt+Tabbing to another window or clicking somewhere else. 4. The popup disappears and you will get a second focus print statement. However, the focus is not actually on the button. Tabbing to try to iterate over controls does not work. To get the shell working again, you can Alt+Tab to another window and then back to it, then the button will have the proper focus rectangle again. Display display = new Display(); Shell master = new Shell(display, SWT.SHELL_TRIM); master.setSize(300, 200); master.setLayout(new GridLayout()); final Shell popup = new Shell(master, SWT.RESIZE | SWT.ON_TOP | SWT.NO_TRIM); popup.setSize(200, 100); popup.addListener(SWT.Deactivate, new Listener() { public void handleEvent(Event event) { popup.dispose(); } }); Button b = new Button(master, SWT.PUSH); b.setText("Popup"); //$NON-NLS-1$ b.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { System.out.println("focusGained"); //$NON-NLS-1$ } }); b.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { popup.setVisible(true); popup.setFocus(); } }); master.open(); while (!master.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose();
*** Bug 332644 has been marked as a duplicate of this bug. ***
I considered working around the problem by listening for a FocusOut event instead but that ended disastrously in an NPE. Exception in thread "main" java.lang.NullPointerException at org.eclipse.swt.widgets.Decorations.saveFocus(Decorations.java:834) at org.eclipse.swt.widgets.Decorations.WM_KILLFOCUS(Decorations.java:1709) at org.eclipse.swt.widgets.Control.windowProc(Control.java:4541) at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341) at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1610) at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2061) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4946) at org.eclipse.swt.internal.win32.OS.PeekMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.PeekMessage(OS.java:3088) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3710) at Main.main(Main.java:169) Display display = new Display(); Shell master = new Shell(display, SWT.SHELL_TRIM); master.setSize(300, 200); master.setLayout(new GridLayout()); final Shell popup = new Shell(master, SWT.RESIZE | SWT.ON_TOP | SWT.NO_TRIM); popup.setSize(200, 100); popup.addListener(SWT.FocusOut, new Listener() { public void handleEvent(Event event) { popup.dispose(); } }); Button b = new Button(master, SWT.PUSH); b.setText("Popup"); //$NON-NLS-1$ b.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { System.out.println("focusGained"); //$NON-NLS-1$ } }); b.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { popup.setVisible(true); popup.setFocus(); } }); master.open(); while (!master.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose();
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.