1 /* 2 * Copyright (c) 2007, 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 /* 25 @test 26 @bug 6246467 27 @summary List does not honor user specified background, foreground colors on XToolkit 28 @author Dmitry Cherepanov area=awt.list 29 @library ../../../../lib/testlibrary 30 @build ExtendedRobot 31 @run main SetBackgroundTest 32 */ 33 34 /** 35 * SetBackgroundTest.java 36 * 37 * summary: 38 */ 39 40 import java.awt.*; 41 import java.awt.event.*; 42 43 public class SetBackgroundTest 44 { 45 46 private static boolean isXAWT = (Toolkit.getDefaultToolkit().getClass().getName().equals("sun.awt.X11.XToolkit")); 47 private static ExtendedRobot robot = null; 48 private static Frame frame = null; 49 50 private static final Color color = Color.red; 51 private static Color roughColor = null; 52 53 private static void initRoughColor(){ 54 55 Canvas canvas = new Canvas(); 56 canvas.setBackground(color); 57 frame.add(canvas, BorderLayout.CENTER); 58 frame.validate(); 59 robot.waitForIdle(500); 60 61 Point loc = canvas.getLocationOnScreen(); 62 Color robotColor = robot.getPixelColor(loc.x + canvas.getWidth()/2, loc.y + canvas.getHeight()/2); 63 roughColor = robotColor; 64 65 System.out.println(" --- init rough color ... "); 66 System.out.println(" color = "+color); 67 System.out.println(" roughColor = "+roughColor); 68 69 frame.remove(canvas); 70 robot.waitForIdle(500); 71 } 72 73 74 private static void test() { 75 if (!isXAWT){ 76 System.out.println(" this is XAWT-only test. "); 77 return; 78 } 79 80 frame = new Frame(); 81 frame.setBounds(400,400,200,200); 82 frame.setLayout(new BorderLayout()); 83 frame.setVisible(true); 84 85 86 try{ 87 robot = new ExtendedRobot(); 88 }catch(AWTException e){ 89 throw new RuntimeException(e.getMessage()); 90 } 91 92 robot.waitForIdle(500); 93 94 initRoughColor(); 95 Component[] components = new Component[] { 96 new Button(), new Checkbox(), new Label(), new List(3, false), 97 new TextArea(), new TextField(), new Choice() 98 }; 99 100 for (Component component : components) { 101 testComponent(new Panel(), component, color); 102 } 103 104 robot.waitForIdle(1500); 105 frame.dispose(); 106 } 107 108 private static void testComponent(Container container, Component component, Color color){ 109 110 component.setBackground(color); 111 112 container.setLayout(new BorderLayout()); 113 container.add(component, BorderLayout.CENTER); 114 frame.add(container, BorderLayout.CENTER); 115 frame.add("Center", container); 116 frame.validate(); 117 robot.waitForIdle(500); 118 119 Point loc = component.getLocationOnScreen(); 120 Color robotColor = robot.getPixelColor(loc.x + component.getWidth()/2, loc.y + component.getHeight()/2); 121 122 System.out.println(" --- test ... "); 123 System.out.println(" container = "+container); 124 System.out.println(" component = "+component); 125 System.out.println(" color = "+color); 126 System.out.println(" roughColor = "+roughColor); 127 System.out.println(" robotColor = "+robotColor); 128 129 if(robotColor.getRGB() != roughColor.getRGB()){ 130 throw new RuntimeException(" the case failed. "); 131 } else { 132 System.out.println(" the case passed. "); 133 } 134 135 container.remove(component); 136 frame.remove(container); 137 robot.waitForIdle(500); 138 } 139 public static void main( String args[] ) throws Exception 140 { 141 test(); 142 } 143 } 144