• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic