1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.Color;
  25 import java.lang.reflect.InvocationTargetException;
  26 
  27 import javax.swing.JDialog;
  28 import javax.swing.JFrame;
  29 import javax.swing.SwingUtilities;
  30 import javax.swing.UIDefaults;
  31 import javax.swing.UIManager;
  32 import javax.swing.plaf.ColorUIResource;
  33 
  34 /**
  35  * @test
  36  * @key headful
  37  * @bug 8033786
  38  * @summary JDialog should update background color of the native peer.
  39  * @author Sergey Bylokhov
  40  */
  41 public final class WrongBackgroundColor {
  42 
  43     public static void main(final String[] args)
  44             throws InvocationTargetException, InterruptedException {
  45         SwingUtilities.invokeAndWait(() -> {
  46             UIDefaults ui = UIManager.getDefaults();
  47             ui.put("control", new ColorUIResource(54, 54, 54));
  48             final JDialog dialog = new JDialog();
  49             final JFrame frame = new JFrame();
  50             frame.pack();
  51             dialog.pack();
  52             final Color dialogBackground = dialog.getBackground();
  53             final Color frameBackground = frame.getBackground();
  54             frame.dispose();
  55             dialog.dispose();
  56             if (!dialogBackground.equals(frameBackground)) {
  57                 System.err.println("Expected:" + frameBackground);
  58                 System.err.println("Actual:" + dialogBackground);
  59                 throw new RuntimeException("Wrong background color");
  60             }
  61         });
  62     }
  63 }