JDK-4490197 : JButton remains pressesd when InputVerifier on JTextField shows dialog.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-08-09
  • Updated: 2001-11-17
  • Resolved: 2001-11-17
Related Reports
Duplicate :  
Relates :  
Description

Name: yyT116575			Date: 08/09/2001


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

When JTextField has set InputVerifier which shows dialog (reporting invalid
input) and user puts some data into such text field and then clicks on button,
the button remains in pressed state after dialog is closed. When you roll mouse
over the button. If mouse pointer is outside of the button, it looks normal. The
button sometimes behaves correctly in the first click onto button. Next try
always brings described behaviour. It is the same on WinNT 4.0, JDK 1.3.1.


import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
 
class VerifierTest extends JFrame {

  public VerifierTest () {
    JTextField tf;
    tf = new JTextField ("Set focus here and click button.");
			   
    getContentPane().add (tf, BorderLayout.NORTH);
    tf.setInputVerifier(new PassVerifier());

    JButton b = new JButton("JButton1");
    getContentPane().add (b, BorderLayout.SOUTH);
                  
    addWindowListener (new MyWAdapter ());
  }

  public static void main (String [] args) {
    Frame f = new VerifierTest ();
    f.pack();
    f.show();
  }

  class MyWAdapter extends WindowAdapter {
    public void windowClosing(WindowEvent event) {
      System.exit (0);
    }
  }
               
  class PassVerifier extends InputVerifier {
    public boolean verify(JComponent input) {
      JTextField tf = (JTextField) input;
      String pass = tf.getText();
      if (pass.equals("pass")) {
        return true;
      }
      String message = "Roll over the 'JButton1' with mouse pointer "
          + "after closing this dialog.\nIt sometimes behaves correctly "
          + "for the first time\n but repeating action brings incorrect "
          + "behaviour of button.";
      JOptionPane.showMessageDialog(null, message , "invalid value", 
          JOptionPane.WARNING_MESSAGE);
      return false;
    }
  }
}
(Review ID: 129667) 
======================================================================

Comments
EVALUATION You shouldn't cause any side effects inside of verify(). Popping up the option pane causes a side effect and we get problems. Moving this to shouldYieldFocus() still results in the shading problem, but fixes the hanging error. ###@###.### 2001-11-16
16-11-2001