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

Discussion in 'Java' started by steve smith, Jul 4, 2003.

  1. steve smith

    steve smith Guest

    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();
    }
     
    steve smith, Jul 4, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. xazos79
    Replies:
    2
    Views:
    6,089
    xazos79
    Mar 1, 2006
  2. Hiten
    Replies:
    1
    Views:
    632
    Vidar Petursson
    May 26, 2004
  3. Marc
    Replies:
    9
    Views:
    214
  4. Replies:
    2
    Views:
    1,143
  5. David
    Replies:
    5
    Views:
    1,710
    Scott Sauyet
    Jul 28, 2011
Loading...

Share This Page