我想将JTextPane
中的制表符\ t的大小设置为4个空格。Java在JTextPane上设置缩进大小
谷歌搜索后,我发现了一些东西,我会包括在这里为我所尝试过的,也许为什么他们失败了。
How do you set the tab size in a JEditorPane?
JTextPane
不是一个普通的文件。
Eclipse中提出了一些错误:
Type mismatch: cannot convert from javax.swing.text.AttributeSet to
javax.print.attribute.AttributeSet
和
The method setParagraphAttributes(javax.swing.text.AttributeSet, boolean) in the type JTextPane is not applicable for the
arguments (javax.print.attribute.AttributeSet, boolean)
http://www.java2s.com/Code/Java/Swing-JFC/TextPaneSample.htm
这页关于造型会谈JTextPane
。代码我改编自它并使它:
MutableAttributeSet set = new SimpleAttributeSet(pane.getParagraphAttributes());
StyleConstants.setLeftIndent(set, 40);
StyleConstants.setRightIndent(set, 40);
* “我想在'JTextPane'设置缩进大小为4。” * 4是什么?像素,人物,..情节? –
我不清楚你用'indent'表示你的意思。这仅仅是TextPane边缘与实际文本之间的空间吗?如果是这样,只需将其边框设置为适当大小的空白边框。 – FredK
我不明白“缩进大小”对您意味着什么。通常缩进是从左边缘开始的空间,并且您不解释为什么'setLeftIndent(...)'方法不起作用。我会认为这是你应该使用的解决方案。但是接下来你还要讨论tabbing,它基于文本窗格的数据,而不是一行文本的起始缩进。 – camickr