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 ?
Devu Shah
Ranch Hand
Joined: Jun 21, 2001
Posts: 50
posted
0
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
Joined: Jun 19, 2001
Posts: 131
posted
0
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.
Narayan Veeramani
Greenhorn
Joined: Jun 06, 2001
Posts: 25
posted
0
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.