javadialogjoptionpane

JOptionPane showOptionDialog


I want to create a showOptionDialog using JOptionPane that has two buttons: Metric and Imperial.
If say, Metric is clicked on, the Metric GUI will load. Conversely, if Imperial is clicked on, then the Imperial GUI will load.

How do I do this?


Solution

  • int choice = JOptionPane.showOptionDialog(null, //Component parentComponent
                                   "Metric or Imperial?", //Object message,
                                   "Choose an option", //String title
                                   JOptionPane.YES_NO_OPTION, //int optionType
                                   JOptionPane.INFORMATION_MESSAGE, //int messageType
                                   null, //Icon icon,
                                   {"Metric","Imperial"}, //Object[] options,
                                   "Metric");//Object initialValue 
    if(choice == 0 ){
       //Metric was chosen
    }else{
       //Imperial was chosen
    }