aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes StyledDocument and Paragraphs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "StyledDocument and Paragraphs" Watch "StyledDocument and Paragraphs" New topic
Author

StyledDocument and Paragraphs

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 863
    
    1
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.


bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StyledDocument and Paragraphs