// Create an action for each radio button
    Action action1 = new AbstractAction("RadioButton Label1") {
        // This method is called whenever the radio button is pressed,
        // even if it is already selected; this method is not called
        // if the radio button was selected programmatically
        public void actionPerformed(ActionEvent evt) {
            // Perform action
        }
    };
    Action action2 = new AbstractAction("RadioButton Label2") {
        // See above
        public void actionPerformed(ActionEvent evt) {
            // Perform action
        }
    };
    
    // Create the radio buttons using the actions
    JRadioButton b1 = new JRadioButton(action1);
    JRadioButton b2 = new JRadioButton(action2);
    
    // Associate the two buttons with a button group
    ButtonGroup group = new ButtonGroup();
    group.add(b1);
    group.add(b2);
    
    // Neither radio button is selected; to select a radio button,
    // see e769 在按钮组中选择一个单选按钮

 

Related Examples

相关文章:

  • 2021-05-23
  • 2021-10-08
  • 2021-10-20
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2021-11-11
  • 2021-07-13
  • 2021-07-09
  • 2022-12-23
  • 2021-11-22
  • 2021-08-02
相关资源
相似解决方案