Using the NetBeans GUI editor, how can I create a JTextField or JFormattedText field that must be validated against a regular expression?

Open the Properties of your JTextField, in the Properties tab look for inputVerifier. Open it Now you'll be asked to introduce the InputVerifier code ftf2. SetInputVerifier(new InputVerifier() { public boolean verifyText(String textToVerify) { Pattern p = Pattern.

Compile("your regexp"); Matcher m = p. Matcher(textToVerify); if (m.matches()) { setComponentValue(textToVerify); return true; } else { return false; } } }) I haven't compiled this code, so could contain errors. But I think you get the idea ;).

Open the Properties of your JTextField, in the Properties tab look for inputVerifier. Open it Now you'll be asked to introduce the InputVerifier code. Ftf2.

SetInputVerifier(new InputVerifier() { public boolean verifyText(String textToVerify) { Pattern p = Pattern. Compile("your regexp"); Matcher m = p. Matcher(textToVerify); if (m.matches()) { setComponentValue(textToVerify); return true; } else { return false; } } }); I haven't compiled this code, so could contain errors.

But I think you get the idea ;).

This isn't the easiest solution, but it is a very powerful one: try spring rich client, where validation could be reached via: public class Validation extends DefaultRulesSource { private Constraint NAME_VALIDATION = all(new Constraint{minLength(3), required()}); public void load() { addRules(new Rules(Person. Class) { @Override protected void initRules() { add("name", NAME_VALIDATION); } }); ... and the gui form is easily created via: TableFormBuilder formBuilder = getFormBuilder(); formBuilder. Add("firstName"); formBuilder.

Add("name"); formBuilder.row(); E.g. Look here for validation or here for more infos. I am using this sucessfully in my open source project ... This way you could create a more general swing component which could be added to the netbeans component palette.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions