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 c
An improved version of @justkt's answer, with the event listener suggested in its comments.
// A non-modal version of JOptionPane.showOptionDialog()
JOptionPane pane = new JOptionPane(arguments, ...);
pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
JDialog dialog = pane.createDialog((Component)parent, "title");
pane.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, ignored -> {
Object selectedValue = pane.getValue();
System.out.print("Out of " + Arrays.toString(pane.getOptions()) + ", ");
System.out.println(selectedValue + " was selected");
dialog.dispose();
});
dialog.setModal(false);
dialog.setVisible(true);