Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I Think the better approach is to use <em>data binding</em>. Check <em>JGoodies Binding</em> at <a href="http://www.jgoodies.com/freeware/libraries/binding/" rel="nofollow">http://www.jgoodies.com/freeware/libraries/binding/</a> but you can try this.</p> <p>Modify your class <code>MyVerifier</code> adding a constructor that accept and array of <code>JComponent</code>. This components will be enabled if validation is true, disabled otherwise.</p> <pre><code>public class MyVerifier extends InputVerifier { JComponent [] components; public MyVerifier(){ } public MyVerifier(JComponent [] components){ this.components = components; } private void enableComponents(){ //enable dependent components if (components != null){ for (JComponent r: components){ r.setEnabled(true); } } } private void disableComponents(){ //disable dependent components if (components != null){ for (JComponent r: components){ r.setEnabled(false); } } } @Override public boolean verify(JComponent input) { String name = input.getName(); if (name == null) { return false; } else if (name.equals("fntf")) { String text = ((JTextField) input).getText().trim(); if (text.matches(".*\\d.*")){ //disable dependent components disableComponents(); return false; // Have Digit } } else if (name.equals("lntf")) { String text = ((JTextField) input).getText(); if (text.matches(".*\\d.*")){ //disable dependent components disableComponents(); return false; } } enableComponents(); return true; } } </code></pre> <p>Then construct your validator passing the list components you want to enable or disabled depending on the result of the validation.</p> <pre><code>fNameTf.setInputVerifier(new MyVerifier(new JComponent[]{maleRb, femaleRb})); </code></pre> <p>This will work not only for <code>JRadioButton</code> but for any <code>JComponent</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload