Results 1 to 5 of 5
Thread: [SOLVED] hyperlinks in JTextPane
- 05-01-2008, 01:48 PM #1
Member
- Join Date
- May 2008
- Posts
- 7
- Rep Power
- 0
[SOLVED] hyperlinks in JTextPane
Hi,
I have a java applet with a JTextPane component, to which text is added like this:
<code>
textPane = new JTextPane();
doc = textPane.getStyledDocument();
doc.insertString(doc.getLength(), message, doc.getStyle(style));
</code>
What I would like is to be able to add hyperlinks to this text, such that clicking one of them will bring up a separate browser window, in which one url or another will load. I know that the way to achieve the browser window is to use
<code>
getAppletContext().showDocument(userUrl,target)
</code>
What I don't know is how to connect a string added to the JTextPane to such a method. Is this at all possible? Or would I need to use components such as labels rather than strings to achieve it? The drawback that I see with such a solution is that it would not be possible to highlight/select text.
Thank you very much for your help
- 05-01-2008, 09:18 PM #2
Member
- Join Date
- May 2008
- Posts
- 6
- Rep Power
- 0
Have you seen the documentation on Sun's website about Editor Panes? If you are just asking how to mark up text inside the pane with HTML, then that article should answer your questions.
- 05-02-2008, 04:12 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yep, using the JEdiotrPane you can easily catch the URL from the HTML text. It's too easy.
- 05-03-2008, 10:42 PM #4
Member
- Join Date
- May 2008
- Posts
- 7
- Rep Power
- 0
Thank you very much for pointing me in the right direction. With the JEditorPane and a HyperlinkListener, my problem was solved.
- 05-05-2008, 03:28 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Nice to here that pal. So, please mark thread as solved form the thread tools menu.
Similar Threads
-
how to show a html document on JTextPane
By mary in forum Advanced JavaReplies: 2Last Post: 08-02-2007, 01:40 PM -
how to insert tables into JTextPane
By osval in forum AWT / SwingReplies: 1Last Post: 07-29-2007, 09:11 AM -
hyperlinks from menu items?
By asterope118 in forum New To JavaReplies: 1Last Post: 07-16-2007, 01:49 PM -
Transparent JTextPane
By Ada in forum AWT / SwingReplies: 1Last Post: 05-31-2007, 09:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks