View Full Version : JButtons color in OS X vs. Windows

Oct 28, 2004, 09:16 PM
Does anyone know if it's possible to change the background color of a Java JButton in OS X? This is a screenshot of a game I had to write for a CS project. It's like Light's Out, where the lights are green when on and black when off. In Windows it's easier to see because the entire button is the color, rather than the space in the background. Is there a way to change this in OS X?

Oct 28, 2004, 10:38 PM
Best I can come up with is to change the look and feel to Metal, so that it looks like the Windows default:

try {
UIManager.setLookAndFeel(new MetalLookAndFeel());
catch(Exception e) {}

JButton button = new JButton(" ");

I'm not seeing an easy way to change button backgrounds with the OS X L&F. I'd imagine it would involve overriding ButtonUI's paint() method... no fun. Anybody have a better solution?

Oct 28, 2004, 10:44 PM
Share a link to the code or PM/email me with it and I'll look at it for you. But tomorrow - I'm going to bed now. Hopefully, someone can fix it for you before then - but I'd be happy to see what I can do.

Oct 28, 2004, 10:49 PM
There is no way to change the button face in the Mac OS X look and feel but if you make a button with a glyph (I've forgotten the class), you can put any image you want in there.

Oct 29, 2004, 12:47 AM
Thanks guys, looks like there's no simple way to do this. :( Oh well.

here's the code I was using to set the colors on the board:

for (int x = 0; x < 8; x++)
for (int y = 0; y < 8; y++)
if (m.isLitAt(x, y))

For the fun of it I tried doing setForeground, but alas, then there was no color :rolleyes: