Java:JOptionPane Radio Buttons
                                        
                    •
                    Java                                    
                I'm working on a simple program to help me calculate mixed liquid things I tried in joptionpane Radio buttons are added to showinputdialog, but I can't link them together When I run the program, nothing appears That's all I have:
JRadioButton nicSelect = new JRadioButton("What is the target Nicotine level? ");
        JRadioButton b1 = new JRadioButton("0");
        JRadioButton b2 = new JRadioButton("3");
        JRadioButton b3 = new JRadioButton("6");
        JRadioButton b4 = new JRadioButton("12");
        JRadioButton b5 = new JRadioButton("18");
        JRadioButton b6 = new JRadioButton("24");
Solution
As an alternative to using multiple jradiobuttons, you can pass a string array to jooptionpane Showinputdialog, via JCombo@R_732_2419 @Provide selection interface:
String[] values = {"0","3","6","12","18","24"};
Object selected = JOptionPane.showInputDialog(null,"What is the target Nicotine level?","Selection",JOptionPane.DEFAULT_OPTION,null,values,"0");
if ( selected != null ){//null if the user cancels. 
    String selectedString = selected.toString();
    //do something
}else{
    System.out.println("User cancelled");
}
                
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        