Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StyledDocument and Paragraphs

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18154
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone know how to programmatically add a paragraph to a Swing StyledDocument? All the examples I have construct a single-paragraph document and leave it at that, and the first/only paragraph is supplied by the document constructor behind the scenes.
 
Brian Cole
Author
Ranch Hand
Posts: 906
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:Anyone know how to programmatically add a paragraph to a Swing StyledDocument? All the examples I have construct a single-paragraph document and leave it at that, and the first/only paragraph is supplied by the document constructor behind the scenes.

I'm not sure what you mean. Presumably this

int pos = yourStyledDocument.getLength();
yourStyledDocument.insertString(pos, "\nfoo", null);

does not meet your requirements?? Because (at least with DefaultStyledDocument) it does increase the paragraph count returned by

yourStyledDocument.getDefaultRootElement().getElementCount()

But then again doing something like this

yourJTextPane.setCaretPosition(pos);
yourJTextPane.replaceSelection("\nfoo");

will do the same thing to the underlying StyledDocument also, without messing with the Document directly.
Perhaps you could explain what you're trying to do.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic