UIManager.getLookAndFeelDefaults().put("Button.background", buttonColor)
For the color of the buttons from JOptionPane dialogs I don't understand why it doesn't work. It should. Maybe a side effect. We don't see all your code.
Try this simple code, you should see only green buttons.
package swing.uimanager;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
public class JFrameWithUIManger extends JFrame {
public static void main(String[] args) {
new JFrameWithUIManger();
}
public JFrameWithUIManger() {
final UIDefaults lookAndFeelDefaults = UIManager.getLookAndFeelDefaults();
lookAndFeelDefaults.put("Button.background", Color.GREEN);
add(new JButton("A button"));
pack();
setVisible(true);
JOptionPane.showMessageDialog(this, "hello I am a message dialog");
JOptionPane.showConfirmDialog(this, "hello I am a question dialog", "do you like me ?", JOptionPane.YES_NO_OPTION);
}
}
For the white background in the title, you have a color (white), so it seems to work. Maybe, a problem in a key-value.
Post it please if you want we understand better.
Edit
After seeing you code, I understood your problem. It's the look and feel used.
You don't use the default look and feel (metal).
Probably, you don't know but all the look and feels in Swing don't born equals.
In deed, some options and mix-options are supported by some look and feels but are not supported by other look and feels.
If you use the default look and feel, you should have less compatibility problem.
The best way to know if it correctly supported is to report to some official docs but it's true that a lot of information about it is dry, with errors, and not detailed
In the link you posted in your comment : http://nadeausoftware.com/articles/2008/11/all_ui_defaults_names_common_java_look_and_feels_windows_mac_os_x_and_linux#Button, the keys displayed in the tables don't mean that values are present or modifiable but that only the keys are present in the LAF.
Each LAF is responsible to take into consideration or not to the key and the possibility to change values associated to the keys.
I tried with the Windows LAF to set only the background color button, it doesn't work either. So, it doesn't seem to be a side effect but it looks like more a missing of support on this feature for the Windows LAF.
Anyway, you can interest to the Nimbus if you want an official, nice and more recent and more flexible look and feel than the classic metal look and feel.
Nimbus document
It's available since the Java SE 6 Update 10.
I agree with you, Metal is ugly. But why don't use nimbus instead of the windows LAF ? It's great. I tried your code which modifies some values of lAF with Nimbus, it seems working nicely. Maybe, you could have some minor modifications to adjust it but the basis should be nice.