Swing/NoWrapTextPane のバックアップ差分(No.3)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/NoWrapTextPane へ行く。
- 1 (2007-09-24 (月) 18:04:06)
- 2 (2007-09-25 (火) 12:23:27)
- 3 (2007-09-25 (火) 16:22:50)
- 4 (2007-09-25 (火) 19:14:19)
- 5 (2012-08-02 (木) 21:04:03)
- 6 (2013-01-31 (木) 22:56:49)
- 7 (2013-05-06 (月) 15:18:45)
- 8 (2013-05-07 (火) 03:20:53)
- 9 (2013-07-24 (水) 21:52:19)
- 10 (2013-07-26 (金) 01:43:55)
- 11 (2013-07-27 (土) 01:01:34)
- 12 (2013-09-06 (金) 15:34:39)
- 13 (2014-11-01 (土) 00:46:09)
- 14 (2014-11-25 (火) 03:03:31)
- 15 (2015-10-29 (木) 16:24:34)
- 16 (2017-03-28 (火) 15:24:43)
- 17 (2017-11-02 (木) 15:34:40)
- 18 (2018-02-01 (木) 19:38:14)
- 19 (2020-01-28 (火) 16:33:24)
- 20 (2021-07-22 (木) 22:11:40)
- 21 (2022-08-20 (土) 22:15:25)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JEditorPaneで長い行を折り返さない
#navi(../)
*JEditorPaneで長い行を折り返さない [#v31d450a]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2007-09-24~
更新日:&lastmod;
#contents
**概要 [#h7ae7cce]
JEditorPaneや、JTextPaneで、行をViewPortの幅で折り返さないよう設定します。
[[Swing - Disabling word wrap for JTextPane>http://forum.java.sun.com/thread.jspa?threadID=622683]]の投稿をそのまま引用しています。
#screenshot
**サンプルコード [#qd3a5388]
#code{{
class NoWrapParagraphView extends ParagraphView {
public NoWrapParagraphView(Element elem) {
super(elem);
}
protected SizeRequirements calculateMinorAxisRequirements(
int axis, SizeRequirements r) {
SizeRequirements req = super.calculateMinorAxisRequirements(axis, r);
req.minimum = req.preferred;
return req;
}
public int getFlowSpan(int index) {
return Integer.MAX_VALUE;
}
}
}}
-&jnlp;
-&jar;
-&zip;
**解説 [#k626f953]
上記のサンプルでは、スパンの必要サイズを計算するcalculateMinorAxisRequirementsメソッドなどをオーバーライドして、行折り返し段落のビュー(ParagraphView)で折り返しが発生しないようなしています。
JEditorPaneやJTextPaneといったStyledDocumentをモデルにしているテキストコンポーネントに非常に長い行をペーストした場合、表示が更新されなくなりますが、折り返しできなくしてしまうと多少ましになるようです。
JTextAreaでも行を非常に長くしてしまうと、カーソルキーの移動などで異常に時間がかかる場合があります。
- 例えば、このサンプルで、カーソルを一番最後に移動し、一行目(非常に長い行)にUp↑キーで移動すると発生する
- [[Swing - Long last line in wrappable textarea hangs GUI (bug in java?)>http://forum.java.sun.com/thread.jspa?threadID=5217158]]
**参考リンク [#ydbfb81a]
- [[Swing - Disabling word wrap for JTextPane>http://forum.java.sun.com/thread.jspa?threadID=622683]]
- [[Non Wrapping(Wrap) TextPane : TextField : Swing JFC : Java examples (example source code) Organized by topic>http://www.java2s.com/Code/Java/Swing-JFC/NonWrappingWrapTextPane.htm]]
**コメント [#rdd302ba]
#comment