InputVerifier causes Button to stay pressed
See with the following simple compilable example
Is this a bug?
Completely locks up on 1.4,
what's wrong - the JOptionPane I take it?
<SSCCE>
import java.awt.*;
import javax.swing.*;
public class VerifyTest extends JFrame {
public VerifyTest() {
setBounds(50,50,200,100);
JPanel pane = new JPanel(new BorderLayout());
setContentPane(pane);
JTextField textField = new JTextField();
pane.add(textField, BorderLayout.NORTH);
JButton button = new JButton("Verify");
pane.add(button, BorderLayout.SOUTH);
textField.setInputVerifier(new InputVerifier() {
public boolean verify(JComponent input) {
return false; // or true.
}
public boolean shouldYieldFocus(JComponent input) {
return JOptionPane.showConfirmDialog( VerifyTest.this,
"Yield focus?\n Yes for true, No for false",
"Test", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
}
});
setVisible(true);
}
public static void main(String[] args) {
new VerifyTest();
}
}

Signature
Mike W
VisionSet - 24 Dec 2004 19:04 GMT
> InputVerifier causes Button to stay pressed
> See with the following simple compilable example
> Is this a bug?
> Completely locks up on 1.4,
> what's wrong - the JOptionPane I take it?
It's okay (well its not!).
I've discovered it's another blasted Swing bug.

Signature
Mike W
S. Khosravani - 25 Dec 2004 06:55 GMT
Been a while since I ran into this, but if memory serves.....
Attempting to show JOptionPane will try to take focus away from the
text field, which causes shouldYieldFocus to be called again, resulting
in an infinite loop. Work around I used was to remove the verifier
before option pane, and reinstall it after....
InputVerifier iv = textField.getInputVerifier();
textField.setInputVerifier(null);
JOptionPane....(...);
textField.setInputVerifier(iv);