1 2 /* 3 * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* 26 * @test 27 * @bug 4251579 28 * @summary Tests if style sheets are working in JLabel 29 * @author Denis Sharypov 30 * @run main bug4251579 31 */ 32 import java.awt.*; 33 import javax.swing.*; 34 35 import sun.awt.SunToolkit; 36 37 public class bug4251579 { 38 39 private static JLabel htmlComponent; 40 41 public static void main(String[] args) throws Exception { 42 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 43 final Robot robot = new Robot(); 44 robot.setAutoDelay(50); 45 46 SwingUtilities.invokeAndWait(new Runnable() { 47 48 @Override 49 public void run() { 50 createAndShowGUI(); 51 } 52 }); 53 54 toolkit.realSync(); 55 56 SwingUtilities.invokeAndWait(new Runnable() { 57 58 @Override 59 public void run() { 60 boolean passed = false; 61 62 Point p = htmlComponent.getLocationOnScreen(); 63 Dimension d = htmlComponent.getSize(); 64 int x0 = p.x; 65 int y = p.y + d.height / 2; 66 67 for (int x = x0; x < x0 + d.width; x++) { 68 if (robot.getPixelColor(x, y).equals(Color.blue)) { 69 passed = true; 70 break; 71 } 72 } 73 74 if (!passed) { 75 throw new RuntimeException("Test failed."); 76 } 77 78 } 79 }); 80 } 81 82 private static void createAndShowGUI() { 83 84 String htmlText = 85 "<html>" 86 + "<head><style> .blue{ color:blue; } </style></head>" 87 + "<body" 88 + "<P class=\"blue\"> should be rendered with BLUE class definition</P>" 89 + "</body>"; 90 91 JFrame mainFrame = new JFrame("bug4251579"); 92 mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 93 94 htmlComponent = new JLabel(htmlText); 95 mainFrame.getContentPane().add(htmlComponent); 96 97 mainFrame.pack(); 98 mainFrame.setVisible(true); 99 } 100 }