Article View: borland.public.jbuilder.java.swing
Article #8731Swing HTML package issue : JEditorPane
From: Fran�ois B�lair
Date: Tue, 25 Jul 2000 00:00
Date: Tue, 25 Jul 2000 00:00
67 lines
2793 bytes
2793 bytes
Salutation,
I have used a JEditorPane to display an HTML content. It's working
perfectly. Now i would like to allow the user to be able to change the font
and color of any string that is currently selected by this user.
==================
What i have done so far
==================
Before using the JEditorPane, i used to have a JTextPane and i played with
the characters attributs like this
private DefaultStyledDocument doc;
private StyleContext sc;
private Style defaultStyle;
private Style selectStyle;
// Create the StyleContext, the document and the pane
sc = new StyleContext();
doc = new DefaultStyledDocument(sc);
// Create a green selection
selectStyle = sc.addStyle("ConstantWidth", null);
StyleConstants.setFontFamily(selectStyle, "monospaced");
StyleConstants.setForeground(selectStyle, Color.green);
doc.setCharacterAttributes(OFFSET, LENGTH, selectStyle, false);
When the user selected a string, its color and font change to the from the
default Style to the select Style.
==================
What i would like to do
==================
Now using a JEditorPane with a text/html format, i tried to reuse the same
code of the previous example.
private HTMLDocument doc;
private StyleSheet sc;
private Style defaultStyle;
private Style selectStyle;
// Create the StyleContext, the document and the pane
sc = new StyleSheet();
doc = new HTMLDocument(sc);
// Create a green selection
selectStyle = sc.addStyle("ConstantWidth", null);
StyleConstants.setFontFamily(selectStyle, "monospaced");
StyleConstants.setForeground(selectStyle, Color.green);
doc.setCharacterAttributes(OFFSET, LENGTH, selectStyle, false);
The problem is that the program hang when i try to call the
setCharacterAttributes. Seems like an infinite loop while processing the
element of the JEditorPane.
I would like to know if the method i am trying to use is the correct one in
the case of a JEditorPane with text/html format. If not, could someone show
me how to change the font and color of an HTML text displayed by the
JEditorPane.
Thank you in advance,
Fran�ois B�lair
Technical Details
Message-ID:
<8ll956$13e9@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111d45,3eb7b1122b2f4d76,start X-Google-Attributes: gid111d45,public From: "Fran�ois B�lair" <belair@orbitek.com> Subject: Swing HTML package issue : JEditorPane Date: 2000/07/25 Message-ID: <8ll956$13e9@bornews.borland.com> X-Deja-AN: 650765340 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Reply-To: "Fran�ois B�lair" <belair@orbitek.com> Newsgroups: borland.public.jbuilder.java.swing