javaswingjtogglebutton

Disable JToggleButton without graying it


I want to set my JToggleButton in a disabled state, i.e. so that the user can't toggle it by clicking. I tried btn.setEnabled(false); but it grays out my icon and I don't want that. Is there any other method which doesn't gray out the icon, but doesn't let the user toggle the button?


Solution

  • but my own custom icon to be displayed.

    You can also specify a "disabled icon" to be used by the toggle button. It could be the same Icon you use by default, or a slightly different icon.

    When you specify your own Icon you don't get the greyed out effect.