Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

InputVerifier  RSS feed

 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Reader,
I have a textfield which is added into a panel, I want to verify the text entered into textfield.
But if I have a JOptionPane in verify method, call to verfiy method goes into an infinit loop.
If I don't have JOptionPane then everything is fine.
Please help.


JOptionPane.showMessageDialog(InputDataPanel.this.getRootPane(), "Please enter a number greater than 0", "Enter Number", JOptionPane.CLOSED_OPTION);
no matter what I put as first argument of JOptionPane(), the code crashes, given me a "NullPointer exception dispose component" and I have to restart JBuilder.
Thank you
Garandi
[ June 24, 2003: Message edited by: Garandi Garandi ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK... the problem is that the JOptionPane grabs focus from the textfield, which runs the textfield's input verifier, which pops up a JOptionPane that attempts to grab focus, which runs the textfield's input verifier, which... well, you get the idea. So the first thing I did was invoke the JOptionPane in another thread. I did this through SwingUtilities.invokeLater(). This worked, but for some reason three dialogs popped up instead of just one. I think this might be because the first gets popped up for the original focus lost event, then another for focus gained back to the textfield (maybe?), then the last for focus lost to the JOptionpane. I fixed this by adding a boolean field to the InputVerifier to check if it is already showing a JOptionPane. Here's the code I got to work...

 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate,
Thank you very much, it worked, I have learned lots from your posting so far.
Thank you once again
Garandi.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!