Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to validate JOptionPane input value

843806Apr 20 2008 — edited Apr 20 2008
I hope I'm in the right place :(

I have this code that takes input from user:
numberOfLoadsPaid = JOptionPane.showInputDialog(null,"How many loads are in this check?", 
                "Check Number: ", JOptionPane.QUESTION_MESSAGE);
number = Integer.parseInt(numberOfLoadsPaid);
however, if the user enters a string of characters instead of actual digits (Integer in this case) it gives me an error.

So, can someone help me put a check on this JOption Pane window so that it actually validates what's being entered?

either WHILE the user is entering the text (like with a focusListener...?)
or when user clicks on OK after entering the value.

thank you very very much for any help or documentation you can provide.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 18 2008
Added on Apr 20 2008
8 comments
1,650 views