2009-12-07 118 views
6

看來我目前的JTextArea實例的行間距約爲1或1.5。任何人都可以告訴我如何更改JTextArea實例中的行距?JTextArea中的行間距

+2

嗨Surjya,你應該upvote並接受你認爲有幫助的答案:-)。你有沒有解決你的問題? – Tom 2009-12-08 06:03:42

回答

11

做谷歌搜索建議你應該使用JTextPane,特別是setParagraphAttributes位於here

的方式來獲得AttributeSet你需要如下:

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

現在只要在set傳遞給setParagraphAttributes方法。

希望這會有所幫助。

+1

很好的答案;但是,我建議從文本窗格中抓取當前的AttributeSet,而不是創建一個新的,這樣你只需要改變你關心的屬性,其他的將保持不變,如下所示: 'MutableAttributeSet set = new SimpleAttributeSet(textPane .getParagraphAttributes());' – Michael 2013-05-13 21:17:21