Swing/LoadsSynchronously のバックアップ差分(No.1)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/LoadsSynchronously へ行く。
- 1 (2014-12-01 (月) 00:02:41)
- 2 (2014-12-01 (月) 14:56:50)
- 3 (2015-03-09 (月) 14:46:02)
- 4 (2015-03-16 (月) 17:28:33)
- 5 (2016-02-17 (水) 16:24:34)
- 6 (2017-04-07 (金) 13:51:51)
- 7 (2017-07-11 (火) 14:59:20)
- 8 (2018-07-11 (水) 16:44:56)
- 9 (2019-05-29 (水) 18:21:39)
- 10 (2019-07-30 (火) 22:10:06)
- 11 (2021-04-06 (火) 17:41:32)
- 12 (2022-08-20 (土) 22:15:25)
- 13 (2022-09-09 (金) 16:09:59)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- title: JEditorPaneに読み込んだHTMLを画像に変換する tags: [JEditorPane, HTMLEditorKit, HTML, ImageIO, Graphics] author: aterai pubdate: 2014-11-30T23:31:13+09:00 description: JEditorPaneに画像付きのHTMLを読み込み、描画が完了した段階で全体のスクリーンショットを撮る方法をテストします。 --- * 概要 [#ha11582f] `JEditorPane`に画像付きの`HTML`を読み込み、描画が完了した段階で全体のスクリーンショットを撮る方法をテストします。 #download(https://lh5.googleusercontent.com/-JPZBF-3MA9o/VHskydE02OI/AAAAAAAANrs/7WXsb2t0ahg/s800/LoadsSynchronously.png) * サンプルコード [#jee2555f] #code(link){{ class ImageLoadSynchronouslyHTMLEditorKit extends HTMLEditorKit { @Override public ViewFactory getViewFactory() { return new HTMLEditorKit.HTMLFactory() { @Override public View create(Element elem) { View view = super.create(elem); if (view instanceof ImageView) { ((ImageView) view).setLoadsSynchronously(true); } return view; } }; } //@Override public Document createDefaultDocument() { // Document doc = super.createDefaultDocument (); // ((HTMLDocument) doc).setAsynchronousLoadPriority(-1); // return doc; //} } }} * 解説 [#zf649ed8] - 左: `default` -- デフォルトの`HTMLEditorKit`を使用 -- `<img>`の画像が非同期で読み込まれるため、スクリーンショットは文字のみ -- 文書の末尾までスクロールした後で、画像のサイズが決まる - 中: `<img width='%d' ...` -- デフォルトの`HTMLEditorKit`を使用 -- `<img>`に予めサイズを属性で指定しているので、スクリーンショット全体のサイズや、スクロールは正常だが、スクリーンショットに画像は表示されない - 右: `LoadsSynchronously` -- `HTMLEditorKit#getViewFactory()`、`ViewFactory#create(Element)`をオーバーライドし、`ImageView`に、`setLoadsSynchronously(true)`を設定して、画像の読み込みを同期的に行うように変更 * 参考リンク [#r178aab7] - [https://community.oracle.com/thread/1353113 setAsynchronousLoadPriority on JTextPane does not seem to work in 1.6 | Oracle Community] -- via: [http://stackoverflow.com/questions/27044987/jscrollpane-does-not-update-its-scroll-to-go-down-to-follow-the-caret-position-b java - JScrollPane does not update its scroll to go down to follow the caret position because of Image in JEditorPane - Stack Overflow] * コメント [#mfb4e5cc] #comment #comment