1

I have been trying to display a messagebox in Swing with JOptionPane by using:

JOptionPane.showMessageDialog(Component parentComponent,
                                     Object message,
                                     String title,
                                     int messageType)
                              throws HeadlessException

The message box looks as shown here:

When I add this line

UIManager.put("OptionPane.background", Color.white);

Option pane looks as shown here:

What should I do in order to get a pure white background in the message box?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

0

You need to make the panel background also white. See this answer

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

Update

I have the following code and it is working fine for me.

import javax.swing.*;
import javax.swing.UIManager;
import java.awt.Color;

public class Dialog {
    public static void main(String[] args){
        UIManager.put("OptionPane.background", Color.WHITE);
        UIManager.put("OptionPane.messagebackground", Color.WHITE);
        UIManager.put("Panel.background", Color.WHITE);
        JOptionPane.showMessageDialog(null, "Invalid Com Port!", "SetColor", JOptionPane.ERROR_MESSAGE);
    }
}

Here is a list of the keys for the UIManager enter image description here

Muhammad
  • 6,725
  • 5
  • 47
  • 54