-
Changing the way JTextPane renders HTML
Hello, I am using Java's JTextPane to display an HTML (with possibly CSS/XML) page. What I want to do is alter the way it renders some tags (like <!-- comment tags -->, or Flash <object> tags) and add additional tags to its rendering capability, both by hardcoding, and possibly (though this is of secondary importance) dynamically, to accomodate XML.
For example, JTextPane, by default, cannot render .swf flash files. It displays two red "??." I would like to be able to change that to a notice stating that JTextPane does not support flash objects.
For another example, It seems to be excluding the end ">" from links, displaying it as text, rather than hiding it with the rest of the HTML. Whether the </a> or <a href....>'s end tag, I cannot tell. I would like to be able to override somehow the way JTextPane renders links to fix that.
So far, I have had no success. The closest I have come is that the solution probaly lies with the HTMLEditorKit class, but I don't know for sure, or I wouldn't be asking here.
So: How can I alter the way JTextPane renders HTML tags, and add tags to its rendering capabilities?
Thanks in advance.
Last edited by Gengar003; 05-11-2006 at 12:33 AM.
-
hi, I get sans problem et 2method
subclassing create() from HTMLEditorKit.HTMLFactory
public View create(Element elem) {
View view;
Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
System.out.println("elem=" + elem.getStartOffset());
System.out.println("elem=" + elem.toString());
if (o instanceof HTML.Tag) {
HTML.Tag tag = (HTML.Tag) o;
if (tag == HTML.Tag.COMMENT) {
view = new GlyphView(elem);
} else if (tag instanceof HTML.UnknownTag) {
view = new InlineView(elem);
} else {
view = super.create(elem);
}
} else {
view = new LabelView(elem);
}
return view;
}
2 - Subclassing HTMLDocument and define new enclosign class HTMLDocument.HTMLReader
public class FullTextHTMLReader extends HTMLDocument.HTMLReader {
/**
* Constructeur par défaut.
*/
public FullTextHTMLReader(int offset) {
super(offset);
// Association de nouvelles actions à de nouveaux tags
// this.registerTag(new HTML.UnknownTag("w"), new HTMLDocument.HTMLReader.CharacterAction());
this.registerTag(new HTML.UnknownTag("root"), new HTMLDocument.HTMLReader.CharacterAction());
}
/////////////////////////////////////////////////////////////
// Fonctions de callback ////////////////////////////////////
/////////////////////////////////////////////////////////////
public void handleText(char[] data, int pos) {
super.handleText(data, pos);
String str = new String(data);
System.out.println("data: " + str + " - offset: " + pos);
}
/////////////////////////////////////////////////////////////
// Fin des fonctions de callback ////////////////////////////
/////////////////////////////////////////////////////////////
}
let's redefine callback functioooonnnnss ! good niiighttt
Last edited by Djakisback; 05-14-2006 at 03:36 AM.
Similar Threads
-
By software_develo in forum .NET
Replies: 13
Last Post: 04-18-2013, 10:50 PM
-
Replies: 0
Last Post: 07-14-2001, 11:01 AM
-
By praveen srinivas in forum Web
Replies: 1
Last Post: 01-16-2001, 09:52 AM
-
Replies: 0
Last Post: 11-17-2000, 09:03 AM
-
By james chung in forum Web
Replies: 0
Last Post: 09-16-2000, 02:41 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks