2014-04-27 36 views
0

我想通过UIManager常量更改我的JOptionPane的背景颜色,文本区域和按钮区域的背景不受影响。不同背景的JOptionPane

我已经发布我的代码:3 enter image description here

Image

如何修改他们的背景呢?

public LoginFINAL() { 
    this.setImagen("/imagenes/FondoLogin.png"); 
    UIManager.put("OptionPane.background",Color.RED); 
    UIManager.put("Panel.background",Color.RED); 
    UIManager.put("Button.background",Color.RED); 
    initComponents(); 
    jLabel3.setVisible(false); 
    setLocationRelativeTo(null); 
    textUsers.requestFocus(); 


} 

这也是我如何调用的JOptionPane

else{ 
      JOptionPane.showMessageDialog(rootPane, "pls"); 

    } 

是不是好些了吗?

+1

是什么问题? –

+0

消息的背景和按钮应该是蓝色的 – user3579230

+0

是你的代码图片吗? –

回答

0

我有同样的问题,这里是我的解决方案:

JOptionPane image

对于具有图像中的问题的人,我发现/适应的解决方案。在我的系统中,我得到了这个结果,无论我是否使用其他人发布的UIManager解决方案,或者制作了一个JDialog并使用了jd.getContentPane()。setBackground(Color.white)。因此,这里的工作围绕我来到了,在这里你循环递归穿过的JOptionPane的每个组件,并设置每个JPanel的背景色:

private void getComponents(Container c){ 

    Component[] m = c.getComponents(); 

    for(int i = 0; i < m.length; i++){ 

     if(m[i].getClass().getName() == "javax.swing.JPanel") 
      m[i].setBackground(Color.white); 

     if(c.getClass().isInstance(m[i])); 
      getComponents((Container)m[i]); 
    } 
} 

在你的代码,你想有消息弹出,沿着线的东西:

pane = new JOptionPane("Your message here", 
       JOptionPane.PLAIN_MESSAGE ,JOptionPane.DEFAULT_OPTION); 
     getComponents(pane); 
     pane.setBackground(Color.white); 
     jd = pane.createDialog(this, "Message"); 
     jd.setVisible(true); 

JOptionPane paneJDialog jd先前所建立的。希望这有助于任何有此问题的人。