如何在jtextarea中设置不同长度的制表位
第一个标签应该停止4
第二个标签应该停在20(如果我从4给出标签,它应该停在20)
第三个标签应该停在30(如果我从0给出标签,它应该停在30)
答案 0 :(得分: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
构造函数。