How to enable a disabled radio button?????????????

S

steve smith

Hi here is the problem i have, i have a number of radio buttons
contained in a buton group, all the buttons bar the first one are
disabled. The buttons are all drawn on a JPanel. What i want to be
able to do is once the enabled button has been selected, I want to
enable the next button in the gropu and also then disable the one that
was previously enabled. Is there any way i can do this, below is the
code i have for setting the group up, and trying the above probelm.
Any help much appreciated Thanks.

/* Function creates a radio button and adds it to the button group */
public JRadioButton getRadioButton(String myString, boolean val)
{
JRadioButton myButton=new JRadioButton(myString);
myButton.setActionCommand(myString);
myButton.addActionListener(myListener);
myButton.setEnabled(val);
group.add(myButton);
return myButton;
}

//adds the radio buttons to the panel, for each transition */
public void addTranPan()
{


for(int i = 0; i < dCreate.char2.size(); i ++)
{
if (i == 0) mPanel.add(getRadioButton(dCreate.char2.elementAt(0).toString(),true));
else
{


mPanel.add(getRadioButton(dCreate.char2.elementAt(i).toString(),false));
}
}
}

public void ChangeButtonState()
{
Component [] components = getContentPane().getComponents();
for (int i = 0; i < components.length; i++)
{
Component c = components;
if (c instanceof JRadioButton)
{
JRadioButton rb = (JRadioButton) c;
rb.setEnabled(false);
}
if (c.getName().equals(ch)) //find button to enable
{
JRadioButton rb = (JRadioButton) c;
rb.setEnabled(true);
break;
}
}
mPanel.repaint();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top