I need to popup some one dialog and get the user confirmation . and I want this dailog should be always top , till user select yes or No option . below is the program I wrote , but now how to get which option has user selected .. i.e Yes or NO ..?
JFrame parent = new JFrame();
JOptionPane optionPane = new JOptionPane("DO you want to continue?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
JDialog dialog = null ;
dialog = optionPane.createDialog(parent, "Next Job process");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
Did you read JOptionPane
's documentation?
There are two ways to use it. One way is to use the various static methods that already return the user's choice or input.
The other way is a direct use (mentioned in the documentation). Once you created a JOptionPane
, you can configure it with various setX
methods. Then you retrieve a JDialog instance, as you already did. After that dialog is close, you can retrieve the user's choice or input with
optionPane.getValue()
or
optionPane.getInputValue()