Creating a JRadioButton Component

Creating a JRadioButton Component

Page 1 of 1

1 Replies - 1344 Views - Last Post: 27 September 2005 - 10:10 AM Rate Topic: -----

#1 wael.salman  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-September 05

Creating a JRadioButton Component

Posted 27 September 2005 - 10:07 AM

// 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);

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a JRadioButton Component

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1858
  • View blog
  • Posts: 20,275
  • Joined: 17-March 01

Re: Creating a JRadioButton Component

Posted 27 September 2005 - 10:10 AM

I'm not sure if you had a question about this or if you're just sharing it. If you're just sharing it, as I said in the email I just sent you, it would be best to put submit it as a "Code Snippet".

You can do that here: http://code.dreamincode.net

If you have a question about this code, please let us know and we'd be happy to help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1