Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-05-2008, 12:05 PM
Member
 
Join Date: May 2008
Posts: 7
olbion is on a distinguished road
insertHTML in a JEditorPane
Hi all,

I have created a JEditorPane which I use in a chat client, with the purpose of interpreting HTML and supporting links. It's working, but I believe I havn't come up with the optimal solution for inserting new html code. I store new strings in a StringBuffer, and then after each new string is appended, I update the HTML content using setText. See my code below.

Code:
package com.olof.chat; import java.awt.Color; import java.awt.Font; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import javax.swing.JEditorPane; import com.olof.applet.AppletActions; public class EditorPaneHyperlinked extends JEditorPane implements HyperlinkListener { private AppletActions aa; private StringBuffer sb; public EditorPaneHyperlinked(AppletActions aa) { setContentType("text/html"); addHyperlinkListener(this); setEditable(false); setFocusable(true); this.aa = aa; sb = new StringBuffer(); } public void append(String message, Font font, Color color) { String html = "<span style=\"color:#" + Integer.toHexString(color.getRGB()).substring(2) + "; font-family:" + font.getFamily() + "; font-size:" + font.getSize() + "pt; font-weight:" + (font.getStyle() == font.BOLD ? "bold" : "") + "\">" + message + "</span>"; append(html); } public void append(String message) { System.out.println("Appending: " + message); sb.append(message); setText(sb.toString()); } public void clear() { sb = new StringBuffer(); setText(""); } public void hyperlinkUpdate(HyperlinkEvent ev) { System.out.println("hyperlink event"); System.out.println("type: "+ev.getEventType()); System.out.println("url: "+ev.getURL()); if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { System.out.println("goTo: "+ev.getURL()); //applet.goTo(ev.getURL(), "_blank"); aa.action(); } } public void newLine() { append("<br/>"); } }
Optimally, I believe I would use something like
Code:
doc = getDocument; doc.insert();
However, if I do that, it does not interpret the HTML anymore. Perhaps I need to use a HTMLDocument, but how do I achieve that?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-05-2008, 01:30 PM
Member
 
Join Date: May 2008
Posts: 22
Jesdisciple is on a distinguished road
You might want to use the Cobra HTML parser, a component of the pure-Java Lobo browser. (But don't ask me for details; I'm a Lobo newbie. )
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Hide the titlebar of a JEditorPane Eranga AWT / Swing 1 03-28-2008 11:28 AM
Copy n' Paste in JEditorPane wraps text in new css..? Sam AWT / Swing 0 02-06-2008 04:55 PM
jeditorpane help parsing html asifsolkar Advanced Java 4 12-14-2007 06:23 AM
JEditorPane drmmr11 Java Applets 0 08-02-2007 07:08 PM
Adding custom highlight to JEditorPane andrewb AWT / Swing 0 06-22-2007 07:48 PM


All times are GMT +3. The time now is 08:08 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org