Thanks for any and all previous help that was given.

What I'm trying to do is when the enter button is pressed that an event is triggered. Here is the code that I have written

    txtGolfName = new Text(container, SWT.BORDER);
    txtGolfName.addKeyListener(new KeyAdapter() {
    @Override
    public void keyReleased(KeyEvent e) {
        for(int index = 0; index < gcName.length(); index++)
            if((txtGolfName.getText()).charAt(index) == '\r')
                System.out.println("Success");
            else
                System.out.println("Not Yet");
        }
    });
    txtGolfName.setBounds(180, 90, 300, 25);

Any help would be greatly be appreciated.

有帮助吗?

解决方案

Just check keyCode of the event:

public void keyReleased(KeyEvent e) {
    if (e.keyCode == SWT.CR)
            System.out.println("Success");
        else
            System.out.println("Not Yet");
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top