1 /* 2 * Copyright (c) 2015, 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 import java.io.BufferedWriter; 24 import java.io.File; 25 import java.io.FileWriter; 26 import java.net.URL; 27 import javax.swing.JEditorPane; 28 import javax.swing.JFrame; 29 import javax.swing.JScrollPane; 30 import javax.swing.SwingUtilities; 31 import javax.swing.text.EditorKit; 32 /* 33 * @test 34 * @key headful 35 * @bug 8031109 36 * @author Victor Dyakov 37 * @summary Rendering HTML code in JEditorPane throws NumberFormatException 38 * @run main bug8031109 39 */ 40 public class bug8031109 { 41 42 private static final String TEXT_HTML = "text/html"; 43 44 public static void main(String[] args) throws Exception { 45 SwingUtilities.invokeAndWait(new Runnable() { 46 47 @Override 48 public void run() { 49 JEditorPane editorPane = new JEditorPane(); 50 editorPane.setEditable(false); 51 EditorKit defaultHtmlEditor = JEditorPane 52 .createEditorKitForContentType(TEXT_HTML); 53 editorPane.setEditorKitForContentType(TEXT_HTML, defaultHtmlEditor); 54 editorPane.setContentType(TEXT_HTML); 55 editorPane.getDocument().putProperty("IgnoreCharsetDirective", 56 Boolean.TRUE); 57 URL url = generateHtmlFile(); 58 String html = "<html>" 59 + "<frameset rows=\"120px, 120 PX , * , 10 *\">\n" 60 + " <frame name=\"top\" src=\"" + url + "\" />\n" 61 + " <frame name=\"center\" src=\"" + url + "\" />\n" 62 + " <frame name=\"main\" src=\"" + url + "\" />\n" 63 + " <noframes>\n" 64 + " <body>\n" 65 + " Your browser does not support frames.\n" 66 + " </body>\n" 67 + " </noframes>\n" 68 + "</frameset>"; 69 editorPane.setText(html); 70 JScrollPane scrollPane = new JScrollPane(editorPane); 71 72 JFrame frame = new JFrame(); 73 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 74 frame.getContentPane().add(scrollPane); 75 frame.setSize(500, 500); 76 frame.setVisible(true); 77 } 78 }); 79 } 80 81 private static URL generateHtmlFile() { 82 File file = new File("hello.html"); 83 try ( 84 FileWriter fw = new FileWriter(file.getAbsoluteFile()); 85 BufferedWriter bw = new BufferedWriter(fw);) { 86 bw.write("<head></head><body>Hello World!</body>"); 87 return file.toURI().toURL(); 88 } catch (Exception e) { 89 throw new RuntimeException(e); 90 } 91 } 92 }