Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background color of button when using Windows LAF?

I have a Java application which uses the native LAF like so:

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

This is working great, however, I am trying to make a button have a red background, but ends up like this:

enter image description here

As you can see, I'm setting background and foreground on the button, but what results is not visually pleasing. Is there a way to have the button draw a red background without subclassing JButton?

like image 649
Tim Avatar asked Dec 27 '22 23:12

Tim


1 Answers

You must understand that under Swing's Look & Feel structure, it's the JButton's UI delegate that does its drawing, not the JButton itself, and so setBackground(...) will not work well in this situation. You'll probably be better off adding an icon to the button instead.

like image 172
Hovercraft Full Of Eels Avatar answered Jan 06 '23 16:01

Hovercraft Full Of Eels