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 * @bug 8033786 37 * @summary JDialog should update background color of the native peer. 38 * @author Sergey Bylokhov 39 */ 40 public final class WrongBackgroundColor { 41 42 public static void main(final String[] args) 43 throws InvocationTargetException, InterruptedException { 44 SwingUtilities.invokeAndWait(() -> { 45 UIDefaults ui = UIManager.getDefaults(); 46 ui.put("control", new ColorUIResource(54, 54, 54)); 47 final JDialog dialog = new JDialog(); 48 final JFrame frame = new JFrame(); 49 frame.pack(); 50 dialog.pack(); 51 final Color dialogBackground = dialog.getBackground(); 52 final Color frameBackground = frame.getBackground(); 53 frame.dispose(); 54 dialog.dispose(); 55 if (!dialogBackground.equals(frameBackground)) { 56 System.err.println("Expected:" + frameBackground); 57 System.err.println("Actual:" + dialogBackground); 58 throw new RuntimeException("Wrong background color"); 59 } 60 }); 61 } 62 }