🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages Started by Nicolas GASNIER Fri, 01 Sep 2006 07:29
JTextPane with HTML problem
#186
Author: Nicolas GASNIER
Date: Fri, 01 Sep 2006 07:29
62 lines
2794 bytes
Hi,

I have a problem with JTextPane and HTML. I want to make a simple editor, 
with the possibility to change some attributes like bold and color.

If I type "this word in bold", then select "word", press bold button, the 
word is effectively displayed in bold in the editor, but it is not aligned 
with the start of the line, and the "in bold" part is completely in the 
right of the editor. I mean, the display is a little messed... Here is the 
HTML code for that phrase :

<p style="margin-top: 0">

      this <b>

      <p>

      </b>in bold

    </p>

The string "word" has been replaced by a new paragraph tag, I don't 
understand if this is because the editor is buggy or if i am doing something 
wrong.

Here is my creation code :

    HTMLEditorKit kit =  new HTMLEditorKit();
    JTextPane messagePane = new JTextPane();
    messagePane.setContentType("text/html");
    messagePane.setEditorKit(kit);

And the code I use to make the selected text in bold :

   MutableAttributeSet style = new SimpleAttributeSet();
   StyleConstants.setBold(style, true);
   StyledDocument doc = messagePane.getStyledDocument();
   int start = messagePane.getSelectionStart();
   int end = messagePane.getSelectionEnd();
   doc.setCharacterAttributes(start, end-start+1, style, true);

Note that I have tried to "register" my style with the text pane :

messagePane.addStyle("Bold", null);
StyleConstants.setBold(style, true);

Then, if I do the same thing, I get the following HTML code:

<p style="margin-top: 0">

      this <b> <Bold> </b>in bold

    </p>

Is there a workaround with this ? Or maybe I do not use the correct method 
to achieve my goal ?
Please help me, I have searched for an answer all around the net, but not 
found any...

Regards.

Nicolas. 
Re: JTextPane with HTML problem
#187
Author: Paul Furbacher [TeamB]
Date: Fri, 01 Sep 2006 14:27
30 lines
1981 bytes
Nicolas GASNIER wrote:

> I have a problem with JTextPane and HTML. I want to make a simple editor, 
> with the possibility to change some attributes like bold and color.
> [...]
> Please help me, I have searched for an answer all around the net, but not 
> found any...

Did you ask in the forums which Sun has for Java, Swing, etc.?
Since this is purely a Swing issue, you might get a better response
there because the audience is probably much more focused on just
Swing problems.  (This JBuilder newsgroup is more focused on using
Swing objects in the IDE, but does frequently involve questions about
basic Swing usage.)


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads