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
ActionListener
to the button. actionPerformed()
to enable the radio buttons. Here is the Oracle tutorial .
Here is the TutorialsPoint tutorial .
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.