Changing the way JTextPane renders HTML


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Changing the way JTextPane renders HTML

  1. #1
    Join Date
    May 2005
    Posts
    22

    Exclamation 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.

  2. #2
    Join Date
    May 2006
    Posts
    2
    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

  1. Help with HTML to PDF conversion with VB.net
    By software_develo in forum .NET
    Replies: 13
    Last Post: 04-18-2013, 10:50 PM
  2. Replies: 0
    Last Post: 07-14-2001, 11:01 AM
  3. changing bgcolor of a row in html table
    By praveen srinivas in forum Web
    Replies: 1
    Last Post: 01-16-2001, 09:52 AM
  4. Changing HTML on the fly
    By John in forum Web
    Replies: 0
    Last Post: 11-17-2000, 09:03 AM
  5. 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center