How to set a background color of a JButton in Java?

后端 未结 6 1499
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 19:33

I am developing a Java Desktop Application. In it I have 4 JButtons on a JPanel. Now I want that whenever a button is clicked its background color

6条回答
  •  攒了一身酷
    2021-01-18 20:36

    You can get the standard background color for buttons from the UIManager:

    button1.setBackground(UIManager.getColor("Button.background"));
    

    As far as I know, the keys could change in different look & feels. Here is a nice webstart app that shows all available keys:

    http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/

提交回复
热议问题