Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2004

Tip: Looking for answers? Try searching our database.

InputVerifier causes Button to stay pressed

Thread view: 
VisionSet - 24 Dec 2004 18:40 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?

<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);


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.