Unable to change background colour for JOptionPane

Posted by Sunil Kumar Sahoo on Stack Overflow See other posts from Stack Overflow or by Sunil Kumar Sahoo
Published on 2010-04-12T04:34:06Z Indexed on 2010/04/12 4:53 UTC
Read the original article Hit count: 281

Filed under:
|
|

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!");
}

}

© Stack Overflow or respective owner

Related posts about joptionpane

Related posts about swing