문제

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