Other |
---|
1.4.1 hopperFixed |
Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
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) ======================================================================
|