Hello all I'm new to the forums, and have a small issue I'm hoping to get help with. I'm basically just trying to add checkboxes in java swing and have only one of them able to be checked at a time. this is what I've got so far, but it doesn't seem to be working. any help is appreciated. Sample code below.
Radio buttons will automatically switch off when another button is switched on.
The trick is that you have to organize them in a group. That way you can have multiple groups of radio buttons and they don't interfere with each other.
I forget what that grouping class is in Swing, so you'll have to look it up, but it should be there.
Another thing to keep in mind is that unlike checkboxes, which have a boolean value for each checkbox, a radio button group has only one value for the entire group, and that value will identify the button that's "ON".
Bjoke: A "Bully Joke". A Statement or action made with malicious intent - unless challenged. At which point it magically transforms into "I was just funnin'" or "What's the matter, can't take a joke?"
What you want is a ButtonGroup. Adding multiple radio buttons to a ButtonGroup instance will thus allow only one of those buttons to be selectable at a time.
Note that it is possible to have none of the buttons selected initially.