Java Swing How to - Force JOptionPane to Stay Open








Question

We would like to know how to force JOptionPane to Stay Open.

Answer

import javax.swing.JComboBox;
import javax.swing.JOptionPane;
/*from w ww. ja v a 2s  .com*/
public class Main {

  public static void main(String[] args) {
    Object[] options = { "Option 1", "Option 2", "Option 3",
        "None of the above" };
    JComboBox optionControl = new JComboBox(options);
    optionControl.setSelectedIndex(3);
    JOptionPane.showMessageDialog(null, optionControl, "Option",
        JOptionPane.QUESTION_MESSAGE);
    System.out.println(optionControl.getSelectedItem());

    String graphSelection = (String) JOptionPane.showInputDialog(null,
        "Choose from the following options...", "Choose From DropDown",
        JOptionPane.QUESTION_MESSAGE, null, options,
        options[3]); 
    System.out.println(graphSelection);

    JOptionPane.showMessageDialog(null, optionControl, "Option",
        JOptionPane.QUESTION_MESSAGE);
  }
}