It seems my current JTextArea instance is having line-spcing about 1 or 1.5. Can anybody tell me how to change the line-spacing in JTextArea instance?
Asked
Active
Viewed 6,542 times
6
-
2Hey Surjya, you should upvote and accept answers that you find helpful :-). Did you work out a solution to your problem? – Tom Dec 08 '09 at 06:03
2 Answers
12
Doing a google search suggests you should be using JTextPane
and in particular the setParagraphAttributes
located here.
The way to get the AttributeSet
you need is as follows:
MutableAttributeSet set = new SimpleAttributeSet();
StyleConstants.setLineSpacing(set, /* your spacing */);
Now just pass in set
to the setParagraphAttributes
method.
Hope this helps.
-
1Good answer; however, I would recommend grabbing the current AttributeSet from the textpane rather than creating a new one, that way you only need to change the attributes you care about and the others will remain, like so: `MutableAttributeSet set = new SimpleAttributeSet(textPane.getParagraphAttributes());` – Michael May 13 '13 at 21:17
0
dont forget to put
textpane.selectAll();
before
textpane.setParagraphAttributes....
or it will not work!

Izzy Kiefer
- 189
- 1
- 4