Is there a way to configure Java setEnabled (false)?

Let's say you have JCheckBoxone that you want to use as an on / off indicator. You use setEnabled(false)to disable mouse clicks on JCheckBox. But setEnabled(false)also highlights checkbox and checkbox text. Is there a way to adjust setEnabled(false)so that redness does not occur?

If this is not possible, is this the only solution, something like lines ButtonModel?

+3
source share
4 answers

You can subclass JCheckBox and override processMouseEvent / processKeyEvent to do nothing.

public class ReadOnlyCheckBox extends JCheckBox {
    public ReadOnlyCheckBox (String text, boolean selected) {
        super(text,selected);
    }

    protected void processKeyEvent(KeyEvent e) {
    }

    protected void processMouseEvent(MouseEvent e) {

    }
}
+5
source

JCheckBox setEnabled CustomJCheckBox , JCheckBox . , ButtonModel.

, - , , , - ? ?

+2

JCheckbox - Sun Bug:

[6289684] JCheckbox

.

+2
0

Source: https://habr.com/ru/post/1790512/


All Articles