6

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?

Surjya Narayana Padhi
  • 7,741
  • 25
  • 81
  • 130
  • 2
    Hey 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 Answers2

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.

pigi5
  • 74
  • 1
  • 10
Tom
  • 21,468
  • 6
  • 39
  • 44
  • 1
    Good 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