如何在不使用 UIManager 的情况下更改 JOptionPane 的背景颜色?

How to change background color of JOptionPane without using UIManager?

我正在尝试更改 JOptionPane 的背景颜色,但这段代码不起作用。

JOptionPane jOptionPane1 = new JOptionPane( );
jOptionPane1.showMessageDialog(this, "Επιτυχής καταχώρηση");
jOptionPane1.setBackground(Color.white);

但是为什么呢?

(我知道 JOptionPane 是一个静态方法,不需要创建新对象,我只需导入 UIManager 即可完成工作。)

这应该可以解决您的问题。

JOptionPane op = new JOptionPane("message", JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 
     op.setOpaque(true);
     op.setBackground(Color.BLACK);
     op.createDialog(this, "Titel").setVisible(true);

如果没有,您应该看看这个解决方法 JOptionPane with different background