• Post Reply Bookmark Topic Watch Topic
  • New Topic

validating user input for number of seats  RSS feed

 
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!