Pergunta

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.

Foi útil?

Solução

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");
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top