Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313117 - KeyListener.keyReleased() of Text widgets is called when key is pressed
Summary: KeyListener.keyReleased() of Text widgets is called when key is pressed
Status: RESOLVED WONTFIX
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: 1.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-17 07:59 EDT by Michael Klein CLA
Modified: 2010-05-27 15:58 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Klein CLA 2010-05-17 07:59:12 EDT
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");
            }
        });
    }

}
Comment 1 Rüdiger Herrmann CLA 2010-05-27 15:58:38 EDT
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.