Unable to change background colour for JOptionPane
- by Sunil Kumar Sahoo
Hi I have created sample progeam which will give same look and feel of a confirm dialog and set the background colour as red.
But I donot know what is the problem that my background colour of option is displayed as the default colour but not red. also i need same look and feel of confirm dialog across all platforms.
Here is the code that I have written. please help me to solve the issue
public class JOptionPaneBackground {
public static void main(String[] args) throws Exception {
// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults();
List<Object> keys = new ArrayList<Object>(uiDefaults.keySet());
Collections.sort(keys, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
return (o1.toString()).compareTo(o2.toString());
}
});
for (Object key : keys) {
System.out.println(String.format("%-40s = %s", key, uiDefaults.get(key)));
}
UIManager.put("OptionPane.background", Color.red);
UIManager.put("Panel.background", Color.red);
JOptionPane.showConfirmDialog(null, "Hello World!");
}
}