JButton on a Mac - Musings

By: Nicholas Duchon


if (background != null) {
  button.setBackground(background);
  button.setOpaque (true);         // ND: getting this to work on a MAC
  button.setBorderPainted (false); // ND: This is needed as well!
}
Or try this: from: java - How to Set the Background Color of a JButton on the Mac OS - Stack Overflow

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 {
 
javax.swing.UIManager.setLookAndFeel( javax.swing.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.


ND.