Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextArea color VRS JEditorPane

Status
Not open for further replies.

jstreich

Programmer
Apr 20, 2002
1,067
US
I'm writing a basic chat (or rather I've written) server/client pair. Now I want to make the username appear in a different color and font style than the stuff the users are saying, and I want URLS to turn into links that will launch the webBrowser. I started out with a JTextArea, and then when I tried to upgrade to a JEditorPane that supports HTML text - but then the message section of the window was just blank.

The code:
Code:
jTextPane.setText(jTextPane.getText() + 
&quot;<b><font color=&quot;blue&quot;>&lt;&quot; + userName + &quot;&gt;:</font></b>&quot;);

Basically an append. As far as I can see this should have worked, but since it didn't I must be missing something.

Thoughts?
 
n/m... I figguered it out. Using a JEditorPane with a &quot;text/html&quot; document the tags
Code:
<head>
</head>
<body>
are added to the beginning, and
Code:
</body>
to the end, if not supplied by the user. So, trying to append using:
Code:
 blah.setText(blah.getText() + &quot;<b>some HTML string</b>&quot;);
results in stuff being added after the close of the body tag, and thus any text appended in this fashion isn't rendered. In case anyone else has this question later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top