an enclosing instance that contains javax.swing.text.StyleContext.NamedStyle is required
- From: "Christian" <java@xxxxxxxx>
- Date: 28 Jun 2006 05:06:38 -0700
Hi!
I try to program a JTextPane that is to hold two different kinds of
lines. The first should be colored green and contain OK-messages; the
second should be colored red and contain error-messages. To achieve
this I have to operate on the text that is displayed in the JTextPane.
To append some text I use the text's insertString-method that takes a
new kind of style as an argument. I got stuck trying this:
try {
StyleContext styleContext = new StyleContext();
StyleContext.NamedStyle namedStyle = new
StyleContext.NamedStyle();
sqlOutput.getDocument().insertString(endPosition, newText,
namedStyle);
}
catch (javax.swing.text.BadLocationException e) {
System.err.println(e);
System.err.flush();
}
It seems to be a general mistake in object-oriented coding of mine for
I get the error-message from the compiler:
an enclosing instance that contains
javax.swing.text.StyleContext.NamedStyle is required
Why shall there be an enclosing instance of the NamedStyle for that is
the one to be created? And if the compiler does not complain about
NamedStyle, how can I tell him that there is a StyleContext named
styleContext as an instance that the compiler seems to miss.
Any help would be great! Kind regards,
Christian
.
- Follow-Ups:
- Prev by Date: Re: JDK 1.6 and JFrame icon
- Next by Date: Transparent JDesktopPane
- Previous by thread: Listeners Blocking Each Other And Needing Events To Trickle Down
- Next by thread: Re: an enclosing instance that contains javax.swing.text.StyleContext.NamedStyle is required
- Index(es):