Skip to content
Advertisement

How to change background color of JOptionPane?

I have added JOptionPane to my application but I do not know how to change background color to white?

`int option = JOptionPane.showConfirmDialog(bcfiDownloadPanel,
            new Object[]{"Host: " + source, panel},
            "Authorization Required",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE
    );

    if (option == JOptionPane.OK_OPTION) {                  }`

Advertisement

Answer

By using the UIManager class

 import javax.swing.UIManager;

 UIManager UI=new UIManager();
 UI.put("OptionPane.background",new ColorUIResource(255,0,0));
 UI.put("Panel.background",new ColorUIResource(255,0,0));

or

 UIManager UI=new UIManager();
 UI.put("OptionPane.background", Color.white);
 UI.put("Panel.background", Color.white);

 JOptionPane.showMessageDialog(null,"Text","SetColor",JOptionPane.INFORMATION_MESSAGE);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement