Change the JCheckBox icon
Answered
Currently I'm implementing an IntelliJ plugin and I have a requirement to change the a JCheckBox icon(tick icon) into something else using png file. I tried bellow codes,
checkBox.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().getImage(imagePath)))
checkBox.setIcon(IconLoader.getIcon(imagePath));
But I was not able to change the checkBox icon. Please let me know if anyone have any opinion on this. Currently I'm using IntelliJ 2017.3 Ultimate for implementation. As far as I know this was working fine for 2016 bellow versions.
Please sign in to leave a comment.
"Tick icon" is a part of Look and Feel and it cannot be set with setIcon() method. Actually setIcon() comes from AbstractButton and this icon is not used for JCheckBox at all. As for the version 2017.3 I'm afraid that code is far too outdated, now JCheckBox's behavior is controlled by DarculaCheckBoxUI and you should override in your own UI method drawCheckIcon(...) to paint desired icon.