2017-08-14 33 views
0

我一直在試圖與JOptionPane顯示在Swing一個消息通過使用:搖擺的JOptionPane背景色不同

JOptionPane.showMessageDialog(Component parentComponent, 
            Object message, 
            String title, 
            int messageType) 
           throws HeadlessException 

消息框看起來如圖here

當我添加此行

UIManager.put("OptionPane.background", Color.white); 

選項窗格看起來如圖所示here

我應該爲了獲得在消息框中純白色背景嗎?

回答

0

您需要使面板背景也變白。見this answer

 UIManager UI = new UIManager(); 
    UI.put("OptionPane.background", Color.white); 
    UI.put("Panel.background", Color.white); 

更新

我有下面的代碼,它是對我工作的罰款。

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對於鍵列表UIManager的 enter image description here

+0

沒有幫助我。任何其他建議請 –

+0

@LakshmiNarasimhanRavichandran複製我的更新代碼並進行測試。 – Muhammad

+0

@Muhammd這也沒有幫助。對於那個很抱歉!! –