[英]Swing JOptionPane background color is different
I have been trying to display a messagebox in Swing with JOptionPane
by using: 我一直在尝试通过使用JOptionPane
在Swing中显示一个消息框:
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 这是UIManager的键的列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.