Insert String into Document with a specified font

I know I can set a font family on an AttributeSet like this:

        SimpleAttributeSet set = new SimpleAttributeSet();
        StyleConstants.setFontFamily(set, "Monospace");

        doc.insertString(
            caretPosition, text, set);

But what I really want to do is set a font:

        StyleConstants.setFont(set, "Courier New");

However, there is no StyleConstants.setFont() method.

So how do I set a font on an AttributeSet? (Note that I am free to use an implementation of AttributeSet other than SimpleAttributeSet. I just happened to use that one.)

(Note that my real goal is to insert a string into a Document using a specified font.)

5
задан Charles 10 May 2011 в 20:24
поделиться