Java Question

VerifyListener not allowing CTRL + X action in SWT Text

When I add a

VerifyListener
to allow typing numbers only to a
Text
, Ctrl+x function is not working. The content of the text box is not cleared. Ctrl+c works fine.

What might be the reason for this?

@Override
public void verifyText(VerifyEvent e) {
char inputChar = e.character;
int keyCode = e.keyCode;
e.doit = Character.isDigit(inputChar) || keyCode == SWT.BS || keyCode == SWT.DEL;
}
}

Answer
@Override
 public void verifyText(VerifyEvent e) {
      char inputChar = e.character;
      int keyCode = e.keyCode;
      String inputString = e.text;
      e.doit = Character.isDigit(inputChar) || keyCode == SWT.BS || keyCode==SWT.DEL||inputString=="";
}

I add a check on the text obtained from the Text widget if it is "", and it is working fine.

Comments