-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
hopper
-
generic, x86
-
generic, windows_nt, windows_2000
Name: ddT132432 Date: 10/23/2001
java version "1.4.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)
There is the class javax.swing.InputVerifier in the SDK 1.4. I used it in my
project under SDK 1.3 and it was OK. But now, under SDK 1.4 it works wrong.
I found two problems that together makes my program unusable.
The first one is that the method shouldYieldFocus(...) is called in the both
cases, when the mouse button is pressed and when it is released. Therefore,
this method is called when user enters any field by the mouse click.
The second one is that the method shouldYieldFocus(...) is called when I am
opening the JOptionPane with the message about error from the body of this
method. It results into the infinete loop. I think, that the field lost focus
when the JOptionPane is displayed.
The source code that demonstrates this problem follows (It is entire file with
the Win.java name). There is main method in this class, you can run it. Thre
are three fields. The first one is without input verifier, the rest ones have
setted input verifier. Click on the second field and you receive the infinite
loop (and messages from the body of shouldYieldFocus(...) method in the
console).
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Win extends JFrame
{
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
public Win()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
Win win = new Win();
}
private void jbInit() throws Exception
{
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.getContentPane().add(jTextField1);
this.getContentPane().add(jTextField2);
this.getContentPane().add(jTextField3);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
InputVerifier iv = new InputVerifier() {
public boolean shouldYieldFocus(JComponent input) {
System.out.println("shouldYieldFocus called");
JOptionPane.showMessageDialog(null, "Something is wrong.");
return false;
}
public boolean verify(JComponent input) {
System.out.println("verify called");
return false;
}
};
jTextField2.setInputVerifier(iv);
jTextField3.setInputVerifier(iv);
this.pack();
this.setVisible(true);
}
}
(Review ID: 134295)
======================================================================
- duplicates
-
JDK-4531346 REGRESSION: InputVerifiers behavior in 1.4 not compatible with 1.3
- Closed
-
JDK-4760432 InputVerifier causes infinite loop when showMessageDialog() called.
- Closed
- relates to
-
JDK-4532517 shouldYieldFocus does not allow side effects in 1.4
- Resolved
-
JDK-4532513 DefaultCaret requests focus for click and pressed causing input verifier to fire
- Closed