JButtons color in OS X vs. Windows

Discussion in 'Mac Programming' started by MacFan26, Oct 28, 2004.

  1. macrumors 65816

    MacFan26

    Joined:
    Jan 8, 2003
    Location:
    San Jose, California
    #1
    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?
     

    Attached Files:

    • 1.jpg
      1.jpg
      File size:
      36.4 KB
      Views:
      148
  2. macrumors 6502

    Joined:
    May 12, 2003
    #2
    Best I can come up with is to change the look and feel to Metal, so that it looks like the Windows default:
    Code:
        ...
        try {
        	UIManager.setLookAndFeel(new MetalLookAndFeel());
        }	
        catch(Exception e) {}
    
        JButton button = new JButton(" ");
        button.setBackground(Color.red);
        ...
    
    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?
     
  3. jsw
    Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #3
    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.
     
  4. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #4
    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.
     
  5. thread starter macrumors 65816

    MacFan26

    Joined:
    Jan 8, 2003
    Location:
    San Jose, California
    #5
    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))
    board[x][y].setBackground(Color.GREEN);
    else
    board[x][y].setBackground(Color.BLACK);
    }

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

Share This Page