Solved

Disable auto close of JOptionPane

Posted on 2004-04-25
3
869 Views
Last Modified: 2007-12-19
sample code as below:

String[] options = {"OK","CANCEL"};
            int input = JOptionPane.showOptionDialog(
                null,   // parentComponent
                newRecordPanel, // message
                "New", // title
                JOptionPane.OK_CANCEL_OPTION,   // optionType
                JOptionPane.PLAIN_MESSAGE,    // messageType
                null,   // icon
                options,    // options
                options[0]  // initialValue
            );

i will do some validation when user click on OK button, if the validation is fail then the JOptionPane show remain there (do not close it). But how can i disable the auto close of the JOptionPane?

thanks
0
Comment
Question by:Kennywen
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10915089
easiest would be to redisplay pane when validationn fails
0
 
LVL 16

Accepted Solution

by:
gnoon earned 25 total points
ID: 10915208
do {

    String[] options = {"OK","CANCEL"};
    int input = JOptionPane.showOptionDialog(
                null,   // parentComponent
                newRecordPanel, // message
                "New", // title
                JOptionPane.OK_CANCEL_OPTION,   // optionType
                JOptionPane.PLAIN_MESSAGE,    // messageType
                null,   // icon
                options,    // options
                options[0]  // initialValue
    );

} while ( input == 0 && !valid( inputvalue ) ); // do again if OK is clicked and not valid input occur
0
 
LVL 16

Expert Comment

by:gnoon
ID: 10915219
just an example of objects's comment.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
Arrays.asList  VS  ArrayList 4 56
Way to decrease size of apk file 9 65
runtime exception 2 27
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question