Changing the background color of a selected JToggleButton

后端 未结 6 2166
暗喜
暗喜 2020-12-07 01:49

I am trying to change the color of a JToggleButton when it has been selected in a reliable, look and feel independent way.

If using the Metal L&F, t

6条回答
  •  青春惊慌失措
    2020-12-07 02:01

    You might see if setIcon() is sufficient for your purpose, but you can also override paint() in the ButtonUI delegate.

    Addendum: @kleopatra's comment is well-taken: changing the UI delegate is not trivial. @mKorbel's recent example shows both the difficulty and versatility of the approach. Its essential advantage is look & feel independence.

    Some less ambitious approaches are mentioned here.

提交回复
热议问题