Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-20-2004, 01:42 PM   #1 (permalink)
freesoft_2000
Code Monkey
 
Join Date: Oct 2004
Posts: 51
freesoft_2000 is on a distinguished road
Question Hyperlinks

Hi everyone,

i need to ask a question which is how does one add a hyperlink in a jtextpane. I am using the default htmldocument class as the default document for the jtextpane.

What i need is for example a user enters some text in the jtextpane and the user highlights it and clicks a button in which a dialog appears to hyperlink the text to for example www.yahoo.com

I also need a way in which when the user clicks on the hyperlink in the jtextpane
the textpane to go to that specific web page.

This is what i have in the button action listener so far

TextPane1 is the instance of the JTextPane class
htmlkit is the instance of the HTMLEditorKit class
htmldoc is the instance of the HTMLDocument class

htmlkit.insertHTML(htmldoc, TextPane1.getCaretPosition(),
"<A href=''>" + "http://www.yahoo.com" + "</A>",0,0,HTML.Tag.A);

When i use the above command line it seems that the word
"http://www.yahoo.com" is inserted in the jtextpane as a hyperlink but when i click it the textpane does not go to the specified page and nothing happens

This is what i am doing in the hyperlink action listener

public void hyperlinkUpdate(HyperlinkEvent event)
{
URL url1 = event.getURL();
HyperlinkEvent.EventType type = event.getEventType();

if(type == HyperlinkEvent.EventType.ACTIVATED)
{

try
{
TextPane1.setPage(url1);
}

catch(Exception e)
{
e.printStackTrace();
}

}

}

The program compiles without errors but i need a way to insert a hyperlink and able to click it an later the jtextpane to be set to that page.

Yes i know the jtextpane must be set to not-editable mode to browse which i have already done in the initilization of the code but did not include it above

I hope some one can help me with this

Thank You

Your Sincerely

Richard West
freesoft_2000 is offline   Reply With Quote
Reply

Bookmarks

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

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



All times are GMT -8. The time now is 01:44 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting