How to Set the Background Color of a JButton on the Mac OS

前端 未结 5 1822
Happy的楠姐
Happy的楠姐 2020-11-30 08:55

Normally with Java Swing you can set the background color of a button with:

myJButton.setBackground(Color.RED);

which would cause the butto

5条回答
  •  萌比男神i
    2020-11-30 09:23

    If you are not required to use Apple's look and feel, a simple fix is to put the following code in your application or applet, before you add any GUI components to your JFrame or JApplet:

     try {
        UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
     } catch (Exception e) {
                e.printStackTrace();
     }
    

    That will set the look and feel to the cross-platform look and feel, and the setBackground() method will then work to change a JButton's background color.

提交回复
热议问题