Friday, April 18, 2008

SWT Text control listener that accepts only numeric data

widthText.addListener(SWT.Verify, new Listener() {

public void handleEvent(Event e) {

String string = e.text;
char[] chars = new char[string.length()];
string.getChars(0, chars.length, chars, 0);
for (int i = 0; i <>
if (!('0' <= chars[i] && chars[i] <= '9')) {
e.doit = false;
return;
}
}
}
});