CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2000
    Location
    Texas
    Posts
    22

    Making multiple radio buttons in a JTable Frame

    I saw the code for the multiple radio buttons on the website, but my question is how would i make it dynamic? For instance, one cell has 2 radio buttons and the next has 4 buttons, etc. I trying to figure this out because I'm working on a program that when a certain button is pressed, depending on the button that is pressed, a different thing will happen, so I would also need a way to get the id/text of the button that was pressed.
    I'm not expecting the entire code, maybe just a little bit to get me started on how to do it.

    "There are no facts, only interpretations."
    -Friedrich Nietzsche

  2. #2
    Join Date
    Sep 2000
    Location
    Melbourne --> Australia
    Posts
    68

    Re: Making multiple radio buttons in a JTable Frame

    Hi
    You can add several Checkboxes to a
    CheckboxGroup and then add this group to a
    Panel, and then add the Panel to the GUI. To add each one to a group do this:

    cb1 = new Checkbox("Label", thegroup, false);
    panelone.add(cb1);//add the first checkbox to the Panel
    add(panelone);// add the first panel to the GUI




    To retrieve the selected Checkbox use:
    getSelectedCheckbox() in the CheckboxGroup
    class, you must use this inside the listener
    method which is "itemStateChanged(ItemEvent e)"

    if you want the Label off the Checkbox,
    you can retrieve it like this:

    public void itemStateChanged(ItemEvent e){
    String selected = thegroup.getSelectedCheckbox().getLabel();
    //then you can do somthing with it like this
    if(selected == "First")
    doSomething();
    else
    doSomethingElse();
    }




    Hope this has helped.
    If you need more help with this you
    can email me at
    [email protected]
    Phill.

    Pleeeese rate me , i am desperate )))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured