简体   繁体   中英

How to make Java Swing Radio Buttons unselectable but not greyed out?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM