Swing/InsertHtmlText のバックアップソース(No.1)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/InsertHtmlText へ行く。
TITLE:JEditorPaneのHTMLDocumentに要素を追加する #navi(../) #tags(JEditorPane, HTMLDocument) RIGHT:Posted by &author(aterai); at 2014-04-28 * JEditorPaneのHTMLDocumentに要素を追加する [#te025c95] `JEditorPane`の`HTMLDocument`から`table`要素を取得し、その子要素として`tr`要素などを追加します。 #download #ref(https://lh5.googleusercontent.com/-hU9bkPgb4Q8/U10bg5XoDfI/AAAAAAAACEI/BJrmelBz93M/s800/InsertHtmlText.png) ** サンプルコード [#gf4627e1] #code(link){{ HTMLDocument doc = (HTMLDocument) editor.getDocument(); Element element = doc.getElement("log"); String ROW_TEXT = "<tr bgColor='%s'><td>%s</td><td>%s</td></tr>"; Date d = new Date(); String tag = String.format(ROW_TEXT, "#FFFFFF", "insertBeforeEnd", d.toString()); try { doc.insertBeforeEnd(element, tag); } catch (BadLocationException | IOException ex) { ex.printStackTrace(); } }} ** 解説 [#q731d6e8] - `insertAfterStart` -- `table`要素の開始タグの後に、子要素として`tr`要素を追加 -- 注: 挿入後のスクロールがおかしい場合がある? - `insertBeforeEnd` -- `table`要素の終了タグの前に、子要素として`tr`要素を追加 //** 参考リンク ** コメント [#m2d1174b] #comment