bug4251579.java revision 11111:4ef86895869c
1145519Sdarrenr 2145510Sdarrenr/* 3145510Sdarrenr * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 4255332Scy * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5145510Sdarrenr * 6145510Sdarrenr * This code is free software; you can redistribute it and/or modify it 7145510Sdarrenr * under the terms of the GNU General Public License version 2 only, as 8255332Scy * published by the Free Software Foundation. 9255332Scy * 10255332Scy * This code is distributed in the hope that it will be useful, but WITHOUT 11145510Sdarrenr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12255332Scy * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13255332Scy * version 2 for more details (a copy is included in the LICENSE file that 14145510Sdarrenr * accompanied this code). 15145510Sdarrenr * 16145510Sdarrenr * You should have received a copy of the GNU General Public License version 17145510Sdarrenr * 2 along with this work; if not, write to the Free Software Foundation, 18145510Sdarrenr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19255332Scy * 20145510Sdarrenr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21145510Sdarrenr * or visit www.oracle.com if you need additional information or have any 22145510Sdarrenr * questions. 23145510Sdarrenr */ 24145510Sdarrenr 25145510Sdarrenr/* 26145510Sdarrenr * @test 27145510Sdarrenr * @bug 4251579 28145510Sdarrenr * @summary Tests if style sheets are working in JLabel 29145510Sdarrenr * @author Denis Sharypov 30255332Scy * @run main bug4251579 31255332Scy */ 32145510Sdarrenrimport java.awt.*; 33255332Scyimport javax.swing.*; 34255332Scy 35255332Scypublic class bug4251579 { 36255332Scy 37255332Scy private static JLabel htmlComponent; 38255332Scy 39255332Scy public static void main(String[] args) throws Exception { 40255332Scy final Robot robot = new Robot(); 41145510Sdarrenr robot.setAutoDelay(50); 42145510Sdarrenr 43145510Sdarrenr SwingUtilities.invokeAndWait(new Runnable() { 44145510Sdarrenr 45145510Sdarrenr @Override 46255332Scy public void run() { 47255332Scy createAndShowGUI(); 48255332Scy } 49255332Scy }); 50255332Scy 51255332Scy robot.waitForIdle(); 52255332Scy 53145510Sdarrenr SwingUtilities.invokeAndWait(new Runnable() { 54255332Scy 55255332Scy @Override 56255332Scy public void run() { 57255332Scy boolean passed = false; 58255332Scy 59255332Scy Point p = htmlComponent.getLocationOnScreen(); 60255332Scy Dimension d = htmlComponent.getSize(); 61255332Scy int x0 = p.x; 62255332Scy int y = p.y + d.height / 2; 63255332Scy 64255332Scy for (int x = x0; x < x0 + d.width; x++) { 65255332Scy if (robot.getPixelColor(x, y).equals(Color.blue)) { 66145510Sdarrenr passed = true; 67145510Sdarrenr break; 68145510Sdarrenr } 69145510Sdarrenr } 70145510Sdarrenr 71145510Sdarrenr if (!passed) { 72145510Sdarrenr throw new RuntimeException("Test failed."); 73145510Sdarrenr } 74145510Sdarrenr 75145510Sdarrenr } 76145510Sdarrenr }); 77145510Sdarrenr } 78145510Sdarrenr 79145510Sdarrenr private static void createAndShowGUI() { 80145510Sdarrenr 81145510Sdarrenr String htmlText = 82145510Sdarrenr "<html>" 83145510Sdarrenr + "<head><style> .blue{ color:blue; } </style></head>" 84145510Sdarrenr + "<body" 85145510Sdarrenr + "<P class=\"blue\"> should be rendered with BLUE class definition</P>" 86145510Sdarrenr + "</body>"; 87145510Sdarrenr 88145510Sdarrenr JFrame mainFrame = new JFrame("bug4251579"); 89145510Sdarrenr mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 90145510Sdarrenr 91145510Sdarrenr htmlComponent = new JLabel(htmlText); 92145510Sdarrenr mainFrame.getContentPane().add(htmlComponent); 93145510Sdarrenr 94255332Scy mainFrame.pack(); 95255332Scy mainFrame.setVisible(true); 96255332Scy } 97255332Scy} 98255332Scy