Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Making radio buttons noneditable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making radio buttons noneditable" Watch "Making radio buttons noneditable" New topic
Author

Making radio buttons noneditable

Bai Shen
Ranch Hand

Joined: Sep 24, 2008
Posts: 323
Is there any way to make a radio button noneditable? I want to use them as an indicator of what's selected, but I don't want people to click and change the selection. Is this possible? TIA.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Bai Shen:
Is there any way to make a radio button noneditable? I want to use them as an indicator of what's selected, but I don't want people to click and change the selection.


Do you mean JRadioButton or JCheckBox? No matter, either way this
is what setEnabled(false) does. That will also cause the LnF to
give an indication to the user that the button is disabled, usually
by using a grey color.

If you want disabled behaviour without the greyed-out color (not
necessarily recommended) you can either mess with the painting
code or you can play tricks with the ButtonModel like this:



bitguru blog
 
GeeCON Prague 2014
 
subject: Making radio buttons noneditable