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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…