【发布时间】:2013-04-07 21:14:48
【问题描述】:
我正在用 Java 制作一个文本编辑器,除了自动缩进之外,我拥有我需要的一切。如果他们转到新行,我将如何使缩进保持不变。我正在为我的编辑器窗口使用 JTextPane。
基本上,如果用户输入新行,我希望新行像之前一样缩进。
到目前为止,这是我的缩进代码:
注意:我的JTextPane是txt,doc部分是JTextPane的DefaultStyledDocument();
SimpleAttributeSet attributes = new SimpleAttributeSet();
TabStop[] tabStops = new TabStop[3];
tabStops[0] = new TabStop(25, TabStop.ALIGN_LEFT, TabStop.LEAD_DOTS);
tabStops[1] = new TabStop(25, TabStop.ALIGN_LEFT, TabStop.LEAD_DOTS);
tabStops[2] = new TabStop(25, TabStop.ALIGN_LEFT, TabStop.LEAD_DOTS);
tabStops[2] = new TabStop(25, TabStop.ALIGN_LEFT, TabStop.LEAD_DOTS);
TabSet tabSet = new TabSet(tabStops);
StyleConstants.setTabSet(attributes, tabSet);
doc.setParagraphAttributes(0, 0, attributes, false);
【问题讨论】:
-
尝试调用 doc.setParagraphAttributes(0, 1, attributes, false);包括最后一段元素