For Programmers: Free Programming Magazines  


Home > Archive > Java Help > July 2006 > Problem Inserting HTML: tags in a JEditorPane









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem Inserting HTML: tags in a JEditorPane
fiziwig

2006-07-31, 10:00 pm

I have a JEditorPane using the HTMLEditorKit.

JEditorPane textRegion;
....
textRegion = new JEditorPane();
textRegion.setEditorKit(new HTMLEditorKit());
.....
When I try to surround the selected text with a bold tag like this:

selected = textRegion.getSelectedText();
textRegion.replaceSelection( "<b>"+selected+</b> );

What I end up with in textRegion is that the less-than and greater-than
symbols have been replaced with their HTML-ified versions:
"&lt;b&gt;selected text&lt;/b&gt;" instead of the actual tags.

How can I get a JEditorPane to take me seriously when I tell it to
insert an HTML tag?

Thanks.

--gary

fiziwig

2006-07-31, 10:00 pm


fiziwig wrote:

I noticed that when my message posted to my reader it had converted the
ampersand-l-t-semicolon back into a less-than character. So that my
post doesn't look totally foolish, my results after
replaceSelection("<b>"+selected+"</b>") are, with spaces added to
prevent converstion:

& l t ; b & g t ; selected text & l t ; / b & g t ;

--gary

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com