bug8015853.txt revision 12677:a4299d47bd00
1</font><font size=2 color="#0000aa"><i>/*
2 * Copyright (c) 2007, 2013, 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 */</font></i><font size=2 color=black>
23<b>import</b> java.io.*;
24<b>import</b> java.net.URL;
25<b>import</b> java.util.Scanner;
26<b>import</b> javax.swing.*;
27<b>import</b> javax.swing.text.html.HTMLEditorKit;
28<b>public</b> <b>class</b> bug8015853 {
29    <b>private</b> <b>static</b> String text = </font><font size=2 color="#00bb00">""</font><font size=2 color=black>;
30    <b>public</b> <b>static</b> <b>void</b> main(String[] args) throws Exception {
31    
32        <b>try</b> {
33            URL path = ClassLoader.getSystemResource(</font><font size=2 color="#00bb00">"bug8015853.txt"</font><font size=2 color=black>);
34            File file = <b>new</b> File(path.toURI());
35            Scanner scanner = <b>new</b> Scanner(file);
36            <b>while</b> (scanner.hasNextLine()) {
37                text += scanner.nextLine() + </font><font size=2 color="#00bb00">"\n"</font><font size=2 color=black>;
38            }
39            scanner.close();
40        } <b>catch</b> (Exception ex) {
41            <b>throw</b> <b>new</b> RuntimeException(ex);
42        }
43        
44        System.out.println(text);
45        
46        SwingUtilities.invokeAndWait(<b>new</b> Runnable() {
47            <b>public</b> <b>void</b> run() {
48                createAndShowGUI();
49            }
50        });
51    }
52    <b>private</b> <b>static</b> <b>void</b> createAndShowGUI() {
53        <b>try</b> {
54            UIManager.setLookAndFeel(</font><font size=2 color="#00bb00">"javax.swing.plaf.metal.MetalLookAndFeel"</font><font size=2 color=black>);
55        } <b>catch</b> (Exception ex) {
56            <b>throw</b> <b>new</b> RuntimeException(ex);
57        }
58        JFrame frame = <b>new</b> JFrame();
59        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
60        JEditorPane editorPane = <b>new</b> JEditorPane();
61        HTMLEditorKit editorKit = <b>new</b> HTMLEditorKit();
62        editorPane.setEditorKit(editorKit);
63        editorPane.setText(text);
64        frame.add(editorPane);
65        frame.setVisible(<b>true</b>);
66    }
67}
68