S-JIS[2007-02-04] 変更履歴

HTMLEditorKit(Swing)

HTMLEditorKitは、 JEditorPaneにおいてHTMLを扱うときに使われるユーティリティーのようなクラス。


独自EditorKitをJEditorPaneに登録する例

	private void initPane(Container c) {
		JEditorPane editor = new JEditorPane();
		editor.setEditorKit(new HteEditorKit());
		〜
	}

独自EditorKitを作成する例

public class HteEditorKit extends HTMLEditorKit {

	public Object clone() {
		HteEditorKit o = (HteEditorKit) super.clone();
		if (o != null) {
			// oの初期化
			// もしメンバー変数を持つなら、ここでoにセットしてやる
		}
		return o;
	}
}

独自HTMLWriterを使用する例

HTMLWriterは、HTML出力を実際に行うクラス。

public class HteEditorKit extends HTMLEditorKit {
〜
	public void write(Writer out, Document doc, int pos, int len)
		throws IOException, BadLocationException {

		//独自のHTMLWriter
		HteWriter w = new HteWriter(out, doc, pos, len);
		w.write();
	}
}

Swing目次へ戻る / Java目次へ戻る
メールの送信先:ひしだま