I'm trying to handle the event of pressing "enter button" when typing in a SWT Text field. Here is what I've done so far:
textField.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent arg0) {
if(arg0.keyCode == SWT.CR) {
//do something here....
}
}
});
This actually works when I hit Enter button, but not when I hit the enter button on the numpad.
Someone knows the constant variable for this button?
Thanks
Try using a traverse listener which is intended for handling things like Enter:
textField.addTraverseListener(new TraverseListener()
{
@Override
public void keyTraversed(final TraverseEvent event)
{
if (event.detail == SWT.TRAVERSE_RETURN)
{
...
}
}
});
我会尝试:
if (arg0.keyCode==SWT.CR || arg0.keyCode==SWT.KEYPAD_CR)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.