This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Java Geeks (Esp bartender!!!)... Today I was messing up with Checkbox and CheckboxGroup. I was able to create 3 radio button with all three enabled!!!.. *** ALL RIGHTS ARE RESERVED... I GOT COPYRIGHTS TO TELL THIS TO SUN!!! ***
OUTPUT in my case was : 3 RADIO BUTTON ("CHICS" , "BABE" , "BLONDE" , "hot") all enabled.
[This message has been edited by maha anna (edited April 10, 2000).]
tony, i think you're supposed to send stuff through the commandline. Ok, psethura, i tried it, and i see your point... The java api says this:
Exactly one check box button in a CheckboxGroup can be in the "on" state at any given time. Pushing any button sets its state to "on" and forces any other button that is in the "on" state into the "off" state.
So, i don't think it's really clear whether the one-at-a-time rule should be used always, or just when someone pushes a radiobutton. On the other hand, the radiobuttons behave quite weird when you use them at first, so perhaps something is wrong.
Joined: Nov 22, 2008
Joined: Nov 22, 2008
Well psethura, I tried your code. There is a learning in this I believe. 1)When you pass the CheckBoxGroup to the constructor, only the last RadioButton is checked. 2)When the checkbox is constructed, and no value for enabling the checkbox as in c[i] = new Checkbox(arr[i] ); Nothing is checked. 3) As in your case, first you have created the checkboxes. As in this case, all of them will be checked by default. So if you now have to set a checkboxgroup, I believe you have to manually take care that only one of them is checked. [This message has been edited by Lionel (edited May 31, 2000).]
I tried your code and got the same result. I found when I clicked the radio buttons off and select them, one at a time, the check box would go off for the previously selected button, automatically. Which is the correct behavior. It seems initializing them to true interferes with this. I even tried initializing only the first one to true, but it still would not un-check automatically. Setting them all to false works fine, however, if you want a default button set on then you'll need a different approach to get the correct behavior. I haven't gotten this to work, yet.
Anxiety does not empty tomorrow of its sorrows, but only empties today of its strength. – Charles Spurgeon