• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

InputVerifier

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic