【问题标题】:Line-Spacing in JTextAreaJTextArea 中的行间距
【发布时间】:2010-12-23 21:00:51
【问题描述】:

看来我当前的 JTextArea 实例的行间距约为 1 或 1.5。谁能告诉我如何更改 JTextArea 实例中的行距?

【问题讨论】:

  • 嘿 Surjya,您应该投票并接受您认为有帮助的答案 :-)。你找到解决问题的办法了吗?

标签: java line spacing jtextarea


【解决方案1】:

进行谷歌搜索表明您应该使用JTextPane,尤其是位于heresetParagraphAttributes

获取你需要的AttributeSet的方法如下:

MutableAttributeSet set = new SimpleAttributeSet();
StyleConstants.setLineSpacing(set, /* your spacing */);

现在只需将set 传递给setParagraphAttributes 方法。

希望这会有所帮助。

【讨论】:

  • 好答案;但是,我建议从文本窗格中获取当前的 AttributeSet 而不是创建新的,这样您只需要更改您关心的属性,其他属性将保留,如下所示:MutableAttributeSet set = new SimpleAttributeSet(textPane.getParagraphAttributes());
猜你喜欢
  • 2013-07-19
  • 1970-01-01
  • 2013-01-22
  • 1970-01-01
  • 2015-08-25
  • 1970-01-01
  • 2012-03-22
  • 1970-01-01
  • 2015-10-07
相关资源
最近更新 更多