Using a jFrame in Java and I have a set of radio buttons however I want these radio buttons to be activated once I have selected a certain button. What's the simplest way to do this? Thanks
Asked
Active
Viewed 6,578 times
0
-
active ??do you mean you want to select all? – Madhawa Priyashantha Jul 13 '15 at 10:35
-
post your code which you tried – Rafiq Jul 13 '15 at 10:37
-
So basically I have 3 radio buttons which I aim to disable, once I have selected a button I want them to be enabled. If that makes any sense. Thanks – Muzz Jul 13 '15 at 10:38
-
I hope you know all radio buttons can't select. You can disable all but you can't enable all of them. Which button you need to enable.? – Dil. Jul 13 '15 at 10:42
-
Sorry I'm new to this. So basically I have a button and 3 radio buttons in my jframe (I've finished off designing the full jf rame). So no proper code as of yet. I need the radio buttons greyed out/disabled but only to activated/working once I have clicked on a button. They are in different panels if that helps. Thanks Muslima. @DiliniRathnayake – Muzz Jul 13 '15 at 10:55
2 Answers
1
- Keep the radio buttons disabled initially.
- Add an
ActionListener
to the button. - Implement
actionPerformed()
to enable the radio buttons.
Here is the Oracle tutorial.
Here is the TutorialsPoint tutorial.

Shrinivas Shukla
- 4,325
- 2
- 21
- 33
0
This is small example to disable radio buttons.
JButton button = new JButton("Click");
JRadioButton one= new JRadioButton("one");
JRadioButton two= new JRadioButton("two");
JRadioButton three = new JRadioButton("three");
one.setEnabled(false);
two.setEnabled(false);
three.setEnabled(false);
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(one);
group.add(two);
group.add(three);
//Add action listener to button
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// enable radion buttons.
one.setEnabled(true);
two.setEnabled(true);
three.setEnabled(true);
}
});
This is a demo idea how this thing working. This is just a basic demo. Button and radio buttons generated. And when click button you can enable them.
01. Generate button and three radio buttons to jframe.
02. Generate button-group and add those radio buttons.
03. In buttons action listener add that "enable radio button" code.
This link will be really helpful to you. Take a good look at that.
You tube link

Dil.
- 1,996
- 7
- 41
- 68
-
Thanks Dilini, I will have a look at what you have posted, I just realised what I need to do is is initially disable the panel with the radio buttons, click the button which is another panel, which will then lead to the radio buttons to be enabled. – Muzz Jul 13 '15 at 11:28
-
Ask that in another question. If this answer is giving good answer please accept it. – Dil. Jul 13 '15 at 11:30