-3

如何在 jtextarea 中设置不同长度的制表位,

第一个标签应该停止 4

第二个标签应该在 20 处停止(如果我从 4 给出标签,它应该在 20 处停止)

第三个标签应该在 30 处停止(如果我从 0 给出标签,它应该在 30 处停止)

4

1 回答 1

2

尝试这样的事情。

StyledDocument document = new DefaultStyledDocument():

SimpleAttributeSet attributes = new SimpleAttributeSet();

TabStop[] tabStops = new TabStop[3];
tabStops[0] = new TabStop(4.0, TabStop.ALIGN_LEFT, TabStop.LEAD_DOTS);
tabStops[1] = new TabStop(20.0, TabStop.ALIGN_LEFT, TabStop.LEAD_DOTS);
tabStops[2] = new TabStop(30.0, TabStop.ALIGN_LEFT, TabStop.LEAD_DOTS);

TabSet tabSet = new TabSet(tabStops);
StyleConstants.setTabSet(attributes, tabSet);
document.setParagraphAttributes(0, 0, attributes, false);

创建 时JTextArea,请使用Document构造函数。

于 2012-07-19T15:05:38.997 回答