Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JEditorPane/4492274/bug4492274.java
38918 views
/*1* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 449227425* @summary Tests if JEditorPane.getPage() correctly returns anchor reference.26* @author Denis Sharypov27* @run main bug449227428*/2930import javax.swing.*;31import javax.swing.text.html.HTMLEditorKit;32import java.awt.*;33import java.io.File;34import java.net.URL;3536public class bug4492274 {3738private static URL page;3940private static JEditorPane jep;4142public static void main(String args[]) throws Exception {4344Robot robot = new Robot();45SwingUtilities.invokeAndWait(new Runnable() {46@Override47public void run() {48createAndShowGUI();49}50});5152robot.waitForIdle();5354SwingUtilities.invokeAndWait(new Runnable() {55@Override56public void run() {57try {58page = new URL(page, "#linkname");59jep.setPage(page);60} catch (Exception e) {61throw new RuntimeException(e);62}63}64});6566robot.waitForIdle();6768if (getPageAnchor() == null) {69throw new RuntimeException("JEditorPane.getPage() returns null anchor reference");70}7172}7374private static String getPageAnchor() throws Exception {75final String[] result = new String[1];7677SwingUtilities.invokeAndWait(new Runnable() {78@Override79public void run() {80result[0] = jep.getPage().getRef();81}82});8384return result[0];85}8687private static void createAndShowGUI() {88try {89File file = new File(System.getProperty("test.src", "."), "test.html");90page = file.toURI().toURL();9192JFrame f = new JFrame();9394jep = new JEditorPane();95jep.setEditorKit(new HTMLEditorKit());96jep.setEditable(false);97jep.setPage(page);9899JScrollPane sp = new JScrollPane(jep);100101f.getContentPane().add(sp);102f.setSize(500, 500);103f.setVisible(true);104105} catch (Exception e) {106throw new RuntimeException(e);107}108}109}110111112