Community
Participate
Working Groups
Build: RAP 1.3 M7 When a KeyListener is registered on a Text widget, the keyReleased method is called immediately when a key is pressed. Here is a snipped to reproduce the behaviour: public class KeyReleasedBug implements IEntryPoint { public int createUI() { Display display = new Display(); Shell shell = new Shell(display, SWT.TITLE); createContent(shell); shell.layout(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return 0; } private void createContent(Shell shell) { shell.setLayout(new GridLayout(1, false)); Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.addKeyListener(new KeyListener() { public void keyReleased(KeyEvent e) { System.err.println("keyReleased"); } public void keyPressed(KeyEvent e) { //System.err.println("keyPressed"); } }); } }
This behavior is intended. KeyListeners were introduced to support cell editors and are limited to this use case. Network latency makes it hard in most cases to transmit every single key up/down event to the server and wait for the response. To get notified about changes in a text widget, you may resort to ModifyListener and VerifyListener.