hi i am using Eclipse Rcp and i need to validate the textbox that only accept the integer value for that i have use the code
txtCapacity.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent EVT) {
if((EVT.character>='0' && EVT.character<='9')){
txtCapacity.setEditable(true);
txtCapacity.setEditable(true);
} else {
txtCapacity.setEditable(false);
System.out.println("enter only the numeric number");
}
}
});
It validates But the Problem with this one is that i cannot use the Backspace key for deleteting the number. and please tell me idea for Validating the decimal too.
thanks in advance
As you are using a listener, you can empty the text field, instead of making it not-editable. You can do something like this, the snippet is based upon your code.
Or better if you use
JFormattedTextField. I’m not sure if you have that in SWT, even if you don’t then try to look for the similar.