JOptionPane showOptionDialog

I want to create showOptionDialog using JOptionPane, which has two buttons: metric and imperial. If, say, a metric is pressed, the Metric GUI will load. Conversely, if you click the "Imperial" button, then the Imperial GUI will load.

How can I do it? Thank you very much.

+4
source share
3 answers
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 } 
+11
source
 Object[] options = {"Metric","Imperial"}; int n = JOptionPane.showOptionDialog(null, "A Message", "A Title", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.DEFAULT_OPTION, null, options, options[1]); System.out.println(n); JFrame metric = new JFrame("Metric"); metric.setBounds(0, 0, 320, 240); JFrame imperial = new JFrame("Imperial"); imperial.setBounds(0, 0, 320, 240); if(n==0){ metric.setVisible(true); }else if(n==1){ imperial.setVisible(true); }else{ System.out.println("no option choosen"); } 
+1
source

Check out http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html there is almost everything you need.

"As I understand it, JOptionPane is great for what it can do, but you can't change the functionality significantly outside of it (not so easy). JDialog is better to inherit if you want to create your own dialog boxes."

0
source

Source: https://habr.com/ru/post/1447309/


All Articles