Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

validating user input for number of seats

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic