Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JCheckBox Single Selection Issue

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys, I'm having an issue setting the JCheckBox so that only one of the options can be selected. I made it so that only one can get selected, that works. But let's say if someone wanted to change there mind and switch to the other option, it won't allow them to do so.

Instance Variables:


The loop that creates every JCheckBox object and adds them to the array list:


This is the part that I worked on to set the selection to only one of them:


If you want further detail it works like this:
~ If I select "public" (accesMod.get(0)), "private" is already unchecked.
~ I have to uncheck "public" in order to check "private"
~ I can't select two at once
~ I CAN switch from "private" to "public" perfectly without having to uncheck anything?

I'd appreciate the help a lot.
 
Marshal
Posts: 74654
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you really mean to post in the Scala forum? Moving thread. [If it really is Scala-related, move it back]

Never, never, write == true or == false.
 
Campbell Ritchie
Marshal
Posts: 74654
335
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds as if JRadioButtons might be a better bet.
 
Ben Jass
Ranch Hand
Posts: 98
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SOLVED, used JRadioButtons instead and combined it with the ButtonGroup.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just for the record, JRadioButton and JCheckBox have identical functionality. Only the appearance, which is determined by the UI delegate, differs.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic