SwingでHTMLを表示する

戻る


import java.util.*;
import java.io.*;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

/**
* <pre>
* $Id: html-swing.html,v 1.1 2009/06/22 16:12:13 kishi Exp kishi $
* ローカルファイルからHTMLを読み込み表示する
* </pre>
@author KISHI Yasuhiro
*/

public class JEditorPaneTest extends JFrame {

    public JEditorPaneTest() {
        setDefaultCloseOperation( EXIT_ON_CLOSE );

        StringBuffer text = new StringBuffer();
        try {
            BufferedReader br = new BufferedReader( new FileReader( "JEditorPaneTest.html" ) );

            String line;
            while ( ( line = br.readLine() ) != null ) {
                text.append( line + "\n" );
            }

            br.close();
        } catch ( Exception e ) {
            e.printStackTrace();
        }

        JEditorPane editorpane = new JEditorPane( "text/html", text.toString() );

        getContentPane().add( BorderLayout.CENTER, editorpane );

        setTitle( "HTMLをSwingで表示してみる" );
        setSize( 640, 480 );

        // pack();
        setVisible( true );

    }

    public static void main( String[] argv ) {
        JEditorPaneTest doit = new JEditorPaneTest();
    }
}


<html>
<body>
  <table border="1">
    <tr>
      <td>テスト</td>
      <td>フォームはどうやって表示するの?</td>
      <td>また、そのうち調べよう</td>
      <td>$С℃</td>
    </tr>
  </table>

<img src="file:flowers.jpg" border="0" width="400" height="400">

</body>
</html>

inserted by FC2 system