0

I am developing a Java Swing App, and I want to use JRadioButton objects to show state. I don't want the user to have the ability to select them. If I use the button's .setEnabled(false) method, the radio button is greyed out.

I don't want the Radio Button to grey out. Is there a way to override this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1104028
  • 381
  • 7
  • 18
  • 6
    *"I don't want the Radio Button to grey out."* And I (as the hypothetical end user) don't want controls on the GUI that appear ..controllable, yet are not! How about honoring the 'path of least surprise' and *not* doing what you are attempting? – Andrew Thompson Mar 11 '15 at 22:39
  • 3
    *"I don't want the Radio Button to grey out"* As another "hypothetical end user" - why? – MadProgrammer Mar 11 '15 at 23:45

1 Answers1

-1

Well You Could Do Something Like:

boolean rButtonEnabled = false;
JRadioButton rButton = new JRadioButton();

rButton.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e) {
            rdbtnNewRadioButton.setSelected(rButtonEnabled);

        }

});

It's not the prettyist solution, but I hope it helps. To store the new value perhaps you can create a new class extending JRadioButton.

While this does not use the .setEnabled(), it is effectively the same

Daniel K.
  • 1,326
  • 2
  • 12
  • 18
  • 1
    *"It's not the prettyist solution [...]."* Yes, that's right. It's hacky and subversive. The downvoter probably agrees. – Radiodef Mar 12 '15 at 00:28
  • @Radiodef While the code may look a bit extreme for such a measure, the actual display of it works perfectly. – Daniel K. Mar 12 '15 at 00:29