将 StyledDocument 添加到 JTextPane

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) {
        //handle error
    }

然后可以将 JTextPane 添加到任何 Swing GUI 表单中。