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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.