• 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

validating user input for number of seats

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the way to validate user input for number of seats obtained via a JOptionPane.showInputDialog ? I want to validate that user has entered only numeric. Do I have to write my own class that is a subclass of JDialog ?
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi rasika,
you can use the while loop i.e u get the user input and check whether it is numeric by catching the number format exception and if not than agian show the optionpane.

Originally posted by Rasika Chitnis:
What is the way to validate user input for number of seats obtained via a JOptionPane.showInputDialog ? I want to validate that user has entered only numeric. Do I have to write my own class that is a subclass of JDialog ?


 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Devu,
Thanks. Yes, I already did that. But my validation code executes after user closes the dialog box. I want to do validation and display error message to user when the user clicks 'OK' button on the dialog box, but prevent the first dialog box from closing.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One approach is to extend JTextField and create your own
MaskEdit Field which only accepts numeric values. For this
you will need to override createDefaultModel() method &
return your own Document object.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic