Tutorial by Examples

try { StyledDocument doc = new DefaultStyledDocument(); doc.insertString(0, "This is the beginning text", null); doc.insertString(doc.getLength(), "\nInserting new line at end of doc", null); MutableAttributeSet attrs = new SimpleAttributeSet(); StyleCons...
try { JTextPane pane = new JTextPane(); StyledDocument doc = new DefaultStyledDocument(); doc.insertString(0, "Some text", null); pane.setDocument(doc); //Technically takes any subclass of Document } catch (BadLocationException ex) { //hand...
StyledDocuments generally do not implement clone, and so have to copy them in a different way if that is necessary. try { //Initialization DefaultStyledDocument sourceDoc = new DefaultStyledDocument(); DefaultStyledDocument destDoc = new DefaultStyledDocument(); ...
Using the AdvancedRTFEditorKit library you can serialize a DefaultStyledDocument to an RTF string. try { DefaultStyledDocument writeDoc = new DefaultStyledDocument(); writeDoc.insertString(0, "Test string", null); AdvancedRTFEditorKit kit = new AdvancedRTFEditorKit(); ...

Page 1 of 1