import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class TestMissingKeyMain extends Shell { /** * Launch the application * @param args */ public static void main(String args[]) { try { final Display display = Display.getDefault(); final TestMissingKeyMain shell = new TestMissingKeyMain(display, SWT.SHELL_TRIM); shell.open(); shell.layout(); dialogShell = new DialogShell(display, SWT.SHELL_TRIM); display.addFilter(SWT.KeyDown, new Listener() { public void handleEvent(Event event) { if (event.keyCode == SWT.ESC) { dialogShell.setLocation(10000, 10000); try { shell.setActive(); } catch (Exception e) { e.printStackTrace(); } } } }); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); creates(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } catch (Exception e) { e.printStackTrace(); } } /** * Create UI task in separate thread */ private static void creates() { Thread thread = new Thread(new Runnable() { public void run() { while (true) { Display.getDefault().asyncExec(new Runnable() { public void run() { } }); } } }); thread.start(); } /** * Create the shell * @param display * @param style */ public TestMissingKeyMain(Display display, int style) { super(display, style); createContents(); } static DialogShell dialogShell; /** * Create contents of the window */ protected void createContents() { setText("SWT Application"); setSize(500, 375); Display.getDefault().addFilter(SWT.KeyUp, new Listener() { public void handleEvent(Event event) { System.out.println("up ---- --------------------" + event); } }); Display.getDefault().addFilter(SWT.KeyDown, new Listener() { public void handleEvent(Event event) { System.out.println("Down ++++++++++++++++++++++++ " + event); } }); Display.getDefault().addFilter(SWT.KeyDown, new Listener() { public void handleEvent(Event event) { if (event.keyCode == SWT.F1) { dialogShell.setActive(); dialogShell.clearText(); if (!dialogShell.isVisible()) dialogShell.open(); else { dialogShell.setTextFocus(); } dialogShell.setLocation(100, 100); } else if (event.keyCode == SWT.ESC) { dialogShell.setLocation(10000, 10000); TestMissingKeyMain.this.setActive(); } } }); final Text button = new Text(this, SWT.NONE); button.setBounds(90, 60, 195, 65); // } @Override protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components } }