0

感谢您之前提供的所有帮助。

我想要做的是当按下回车按钮时触发事件。这是我写的代码

    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);

任何帮助将不胜感激。

4

1 回答 1

2

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");
    }
}
于 2013-01-23T11:44:43.827 回答