I am working on an application which pops up a JOptionPane when a certain action happens. I was just wondering if it was possible that when the JOptionPane does pop up how can you still use the background applications. Currently when the JOptionPane pops up I can't do anything else until I close the JOptionPane.
EDIT
Thanks for the reply guys and the information. Think ill leave this function out of the application cause it looks like it could be more hassle than necessary.
All the dialogs that JOptionPane provides are modal. To create a non-modal dialog, you must use the JDialog class directly. class. It adds to Dialog a root pane and support for a default close operation.
JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something. For information about using JOptionPane , see How to Make Dialogs, a section in The Java Tutorial. Asks a confirming question, like yes/no/cancel.
Java AWT Programming Project The JOptionPane is used instead of JDialog to minimize the complexity of the code. The JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning, and error) or the custom icons specified by the user.
JOptionPane is a nice way to throw together a few dialog boxes and get a GUI, but it doesn't give us the flexibility we really want. But with power and flexibility come complexity. The basic class we start with is a JFrame.
Within your Java application, I think you're out of luck: I haven't checked, but I think that JOptionPane's showXXXDialog methods pop up a so-called modal dialog that keeps the rest of the GUI from the same JVM inactive.
The JOptionPane is used instead of JDialog to minimize the complexity of the code. The JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning, and error) or the custom icons specified by the user. JOptionPane class is used to display four types of dialog boxes
These dialog boxes are used to display information or get input from the user. The JOptionPane class inherits JComponent class. It is used to create a JOptionPane with a test message.
A Dialog can be modal. When a modal Dialog is visible, it blocks user input to all other windows in the program. JOptionPane creates JDialogs that are modal. To create a non-modal Dialog, you must use the JDialog class directly. Starting with JDK6, you can modify Dialog window modality behavior using the new Modality API.
The documentation explicitly states that all dialogs are modal when created through the showXXXDialog methods.
What you can use is the Direct Use method taken from the docs and the setModal method that JDialog inherits from Dialog:
JOptionPane pane = new JOptionPane(arguments);
// Configure via set methods
JDialog dialog = pane.createDialog(parentComponent, title);
// the line below is added to the example from the docs
dialog.setModal(false); // this says not to block background components
dialog.show();
Object selectedValue = pane.getValue();
if(selectedValue == null)
return CLOSED_OPTION;
//If there is not an array of option buttons:
if(options == null) {
if(selectedValue instanceof Integer)
return ((Integer)selectedValue).intValue();
return CLOSED_OPTION;
}
//If there is an array of option buttons:
for(int counter = 0, maxCounter = options.length;
counter < maxCounter; counter++) {
if(options[counter].equals(selectedValue))
return counter;
}
return CLOSED_OPTION;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With