Search code examples
javaswingsubstance

Override default foreground color for Flamingo's JCommandButton


I'm using Flamingo/Substance in a Swing application and can't figure out a simple way to affect the text color for a JCommandButton. Explicitly setting the foreground color seems to have no effect:

JCommandButton button = new JCommandButton("Button");
button.setForeground(Color.red);

Do I have to extend JCommandButton to do this? If so, how do I override this behavior? Thanks.


Solution

  • I'm not sure if this is the preferred way of doing it, but I ended up extending the delegate to get the result I wanted:

    class CustomCommandButtonUI extends BasicCommandButtonUI {
      @Override
      protected Color getForegroundColor(boolean isTextPaintedEnabled) {
        return Color.red;
      }
    }