Auf Thema antworten

Eine Möglichkeit wäre auch noch, eine JTextPane zu verwenden. Farben enthält mein Beispiel nicht, aber vielleicht ist es dennoch nützlich:


[code=Java]        String newline = "\n";

        String[] initString = {

                "This is an editable JTextPane, ",    // regular

                "another ",                           // italic

                "styled ",                            // bold

                "text ",                              // small

                "component, ",                        // large

                "which supports embedded components..." + newline,// regular

                " " + newline,                        // button

                "...and embedded icons..." + newline, // regular

        };


        String[] initStyles = { "regular", "italic", "bold", "small", "large",

                "regular", "button", "regular" };


        JTextPane textPane = new JTextPane();

        StyledDocument doc = textPane.getStyledDocument();

        addStylesToDocument(doc);


        try {

            for (int i = 0; i < initString.length; i++) {

                doc.insertString(doc.getLength(), initString[i], doc

                        .getStyle(initStyles[i]));

            }

        } catch (BadLocationException ble) {

            System.err.println("Couldn't insert initial text into text pane.");

        }[/code]



Oben