My question is:
I want the Text field in Eclipse RCP to allow only the digits to be keyed in as inputs and the requirement is that it should allow only up to ‘x’ (let’s say x=5) characters.
How can I accomplish it in RCP ?
I’ve tried the code like:
txtInput.addListener(SWT.Verify, new DecimalText(
txtInsuranceValue, 8, 1000.00));
where txtInputis a Text field. But this listener failed when I made repeated input into this field at run time.
Any alternatives please ?
This will set the maximum number of characters in your Text control to five and allow only digits to be entered:
EDIT: I’ve modified my answer to allow a user to also set text with “setText(String string)” while still disallowing non-digit characters.