Hello! Such a problem: there is a primitive dialog box

JOptionPane.showMessageDialog(null, "<html><head><style>body {background-color: #3b3b3b; }</style><meta charset='UTF-8'></head>" + "<body><span style='line-height: 1.5';>" + "<center><b><font color='#de6909' size=8>Благодарности</font></b></center><p></p>" + "тут текст<p></p><p></p>" + "</font>" + "</span></body>" + "</html>", "Благодарности", JOptionPane.PLAIN_MESSAGE); 

Trying to paint the window through the UIManager:

 UIManager UI=new UIManager(); UI.put("OptionPane.background",new ColorUIResource(59,59,59)); 

The result is this:

What's going on

Can you please tell me how to paint the background, which is white in the screenshot (next to the OK button)?

    1 answer 1

    In the bowels of the BasicOptionPaneUI , which is responsible for the appearance of the JOptionPane , three JPanel , so you can paint it like this:

     // метод put у UIManager - статический, создавать его экземпляр не нужно UIManager.put( "OptionPane.background",new ColorUIResource(59,59,59) ); UIManager.put( "Panel.background",new ColorUIResource(59,59,59) ); 

    If the color of the panels in the entire program cannot be changed, you can save the old value of "Panel.background" before calling showMessageDialog and then return it back, or write and register your implementation of BasicOptionPaneUI .

    • Everything worked out! Thank you so much! - NowenUI 2:26 pm