javaswingjbuttonuimanager

How to change the color of a disabled jbutton?


I'm implementing a Mastermind game and there is a board which has the plays (left) and the results (right). I have numerous buttons which some are enabled and other disabled. These buttons are associated to the colors of a play or a result. https://i.sstatic.net/E2L94.jpg "working board" In the image, there are 2 types of buttons, the enabled, green boarded, and the disabled, red boarded. When I try to use an UImanager, the nimbus, it puts all the disabled buttons of the same color, and I don't want that. https://i.sstatic.net/FSO4T.jpg "not working board"

I've tried to simply setBackground of a button and it didn't work.

How can I put a specific color to a button and only that button using the UIManager? That way I can have each button with it's color.


Solution

  • An button can't be changed while using UIManager.