Swing/TabSize のバックアップの現在との差分(No.10)
TITLE:JTextPaneでタブサイズを設定
Posted by terai at 2005-04-25
JTextPaneでタブサイズを設定
JTextPaneでタブサイズを設定します。Swing [Archive] - tabsize in JTextPaneからの引用です。- category: swing folder: TabSize title: JTextPaneでタブサイズを設定 tags: [JTextPane, StyledDocument, SimpleAttributeSet, TabSet, TabStop] author: aterai pubdate: 2005-04-25T00:01:26+09:00 description: JTextPaneのStyledDocumentが使用するパラグラフ属性として、タブストップが展開する文字数を設定します。 image:
概要
JTextPane
のStyledDocument
が使用するパラグラフ属性として、タブストップが展開する文字数を設定します。
- &jnlp;
- &jar;
- &zip;
Screenshot
Advertisement
#screenshot
サンプルコード
#spanend
#spandel
textpane.setFont(new Font("monospaced", Font.PLAIN, 12));
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
textpane.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
#spanend
FontMetrics fm = textpane.getFontMetrics(textpane.getFont());
int charWidth = fm.charWidth('m');
int tabLength = charWidth * 4;
TabStop[] tabs = new TabStop[10];
#spandel
for(int j=0;j<tabs.length;j++) {
#spanend
tabs[j] = new TabStop((j+1)*tabLength);
#spanadd
for (int j = 0; j < tabs.length; j++) {
#spanend
tabs[j] = new TabStop((j + 1) * tabLength);
}
TabSet tabSet = new TabSet(tabs);
SimpleAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setTabSet(attrs, tabSet);
int l = textpane.getDocument().getLength();
textpane.getStyledDocument().setParagraphAttributes(0, l, attrs, false);
解説
JTextAreaはsetTabSizeメソッドでタブサイズを指定することができますが、JTextPaneでは、上記のサンプルのような方法でタブサイズを指定します。解説
-
JTextArea
- JTextArea#setTabSize(int)メソッドでタブサイズの指定が可能
-
JTextPane
-
JTextPane
からStyledDocument
を取得し、TabStop
から作成したTabSet
をパラグラフ属性として追加することでタブの幅を指定
-
参考リンク
参考リンク
コメント
- ãã®éãä¿å¤ªéã®è©©ãã http://www.stlouisbusinesslist.com/business/5021837.htm?info=viagra viagra 袢袳被袺袱 -- viagra?