-1

I am trying to get my java application to add a double spacing feature, using StyleDocs and StyleConstants. So far this is what I have.

   void doSpace(){

   StyleConstants.setLineSpacing(style, 5);

    try { doc.insertString(doc.getLength(), " ",style); }
    catch (BadLocationException r){}
    }

I apply this and nothing happens. I believe my error is in the doc.insertString However this has worked when trying to change the font size, and color. Thanks for the help

user1924782
  • 33
  • 1
  • 6

1 Answers1

1

When you just insert the text with style (AttributeSet) it is applied to text (character) element (leaves).

To apply line spacing call

yourStyledDocument.setParagraphAttributes(..., yourStyleWithLineSpacing);

This way the line spacing will be applied to paragraph.

mKorbel
  • 108,320
  • 17
  • 126
  • 296
StanislavL
  • 55,186
  • 9
  • 58
  • 88