Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) {                  }`
like image 371
itro Avatar asked Jan 30 '12 13:01

itro


People also ask

What are the 4 JOptionPane dialog boxes?

The JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning, and error) or the custom icons specified by the user.


2 Answers

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);
like image 156
Mob Avatar answered Oct 10 '22 10:10

Mob


Use this code if you have the same problem as erik k atwood. This solves the problem:

UIManager.put("OptionPane.background", Color.WHITE);
UIManager.getLookAndFeelDefaults().put("Panel.background", Color.WHITE);
like image 27
Zsolt Ébel Avatar answered Oct 10 '22 10:10

Zsolt Ébel