TITLE:JTextPaneでタブサイズを設定
#navi(../)
RIGHT:Posted by [[terai]] at 2005-04-25
*JTextPaneでタブサイズを設定 [#bc0a9823]
JTextPaneでタブサイズを設定します。[[Swing [Archive] - tabsize in JTextPane>http://forums.sun.com/thread.jspa?threadID=285096]]からの引用です。

-&jnlp;
-&jar;
-&zip;

#screenshot

**サンプルコード [#f20b0404]
#code{{
textpane.setFont(new Font("monospaced", Font.PLAIN, 12));
FontMetrics fm = textpane.getFontMetrics(textpane.getFont());
int charWidth = fm.charWidth('m');
int tabLength = charWidth * 4;
TabStop[] tabs = new TabStop[10];
for(int j=0;j<tabs.length;j++) {
  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);
}}

**解説 [#w2ad23ff]
JTextAreaはsetTabSizeメソッドでタブサイズを指定することができますが、JTextPaneでは、上記のサンプルのような方法でタブサイズを指定します。

**参考リンク [#ha0226f7]
-[[Swing [Archive] - tabsize in JTextPane>http://forums.sun.com/thread.jspa?threadID=285096]]

**コメント [#h20d6278]
- この間も俊太郎の詩をお  http://www.stlouisbusinesslist.com/business/5021837.htm?info=viagra viagra   袢袳被袺袱   -- [[viagra]] &new{2010-03-08 (月) 12:21:45};

#comment