StyledDocument document = new DefaultStyledDocument();
SimpleAttributeSet attributeSet = new SimpleAttributeSet();
StyleConstants.setBold(attributeSet, true);
StyleConstants.setAlignment(attributeSet, StyleConstants.ALIGN_JUSTIFIED);
try {
document.insertString(document.getLength(), text, attributeSet);
} catch (BadLocationException e) {
// Normally cannot happen.
textPane.setText(text);
e.printStackTrace();
}