-1

What my program does is allow the user to select from a list of movies and decide whether they want to rent or purchase each movie. Here is my code:

 public void addMovie(JFrame framePassed, JLabel moviePassed, JCheckBox movieCheckBoxPassed){



    if (movieCheckBoxPassed.isSelected() == true)
    {
    framePassed.add(moviePassed);

       bg2.add(rentButton);  
       bg2.add(purchaseButton); 

       framePassed.add(rentButton);
       framePassed.add(purchaseButton);
    }//end if

    else
    {
    framePassed.remove(moviePassed);

    }//end else
   // movieList.add(new Movie());
    framePassed.setSize(1000, 1000);
    framePassed.setVisible(true);



  }//end method

The moviePassed is added to the framePassed but the radio buttons are not appearing. Any help is appreciated. Thank you in advance.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
K-Rob
  • 11
  • 3
  • 1. Best if you could create and post a small compilable and runnable program that demonstrates what you're trying to do, a [mcve] (read the link). 2. You don't want to add and remove components directly to and from a JFrame. That's madness. 3. Better to add and remove from JPanels. 4. Better still to use JLists or JTables. 5. You don't tell us key information including layout managers used. In all a very incomplete question that you'll want to improve. – Hovercraft Full Of Eels May 04 '16 at 01:17
  • As suggested above the few random lines doesn't give us the context of how the code is actually used. However I did notice one thing. You appear to be attempting to add the radio buttons to two different components. A component can only have a single parent, so your posted code won't work. – camickr May 04 '16 at 03:16

1 Answers1

-1

Try grouping your radio buttons:

ButtonGroup optionsButtonGroup = new ButtonGroup();
optionsButtonGroup.add(rentButton);
optionsButtonGroup.add(purchaseButton);
PeaceIsPearl
  • 329
  • 2
  • 6
  • 19
  • How does this help him in his main problem -- that the JRadioButtons don't show up in his GUI? ButtonGroups have nothing to do with component display and all to do with behavior -- something not addressed in the original question. I think that you're providing an answer way too early, before we even know why his program is not functioning correctly. – Hovercraft Full Of Eels May 04 '16 at 01:32