File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 15624
    
  15

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: 862
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: StyledDocument and Paragraphs
 
Similar Threads
Styled TextAreas
Get LeafElement from DefaultStyledDocument by Point(x,y) ??
JTextArea Formatting
JTextArea & Cursor
Jtextarea