From your code i guess public class MyVerifier
is an inner class of AddUserDialog2
. If so then you should be able to disable JRadioButton
inside the boolean verify(JComponent input)
function, at the beginning and at the end. This is the easiest solution i can think of:
public boolean verify(JComponent input) {
maleRb.setEnabled(false);
femaleRb.setEnabled(false);
String name = input.getName();
if (name.equals("fntf")) {
String text = ((JTextField) input).getText().trim();
if (text.matches(".*\\d.*")) return false; // Have Digit
} else if (name.equals("lntf")) {
String text = ((JTextField) input).getText();
if (text.matches(".*\\d.*")) return false;
}
maleRb.setEnabled(true);
femaleRb.setEnabled(true);
return true;
}
But doing so, I am afraid you won't intercept the disable effect. In your code:
fNameTf.setName("fntf");
fNameTf.setInputVerifier(new MyVerifier());
lNameTf = new JTextField(10);
lNameTf.setName("lntf");
lNameTf.setInputVerifier(new MyVerifier());
maleRb = new JRadioButton("Male");
maleRb.setInputVerifier(new MyVerifier());
maleRb.setName("male");
femaleRb = new JRadioButton("Female");
femaleRb.setName("Female");
femaleRb.setInputVerifier(new MyVerifier());
you don't need to create 4 objects for common input verification. Just create one and pass it to these four input object. Again, when you are passing "male" to JRadioButton it is setting it's text feild but not name. so you need to use maleRb.setName("male")
and femaleRb.setName("female")
and the error will disappear.