Java Swing custom text JEditorPane


I have a list of Objects (the model) that are constantly appended to (similar to a log file) and I'd like to display as rich text in a JEditorPane (the view). How can I glue them together? doesn't seem to give enough information to use.

Best Solution

You can use DefaultStyledDocument together with AttributeSet:

SimpleAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setBold(attr , true);
StyleConstants.setForeground(attr, Color.RED); 
document.insertString(document.getLenght(),"yourstring", attr))