Mar 26th, 2008, 05:25 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Clickable link to get the browser in a JLable
Hi all,
I want to add a html link to a web page on a JLabel. I try something this.
Code:
String htmtString = "<html><head></head><body><a href = \"http://www.google.com/\">Google</a></body></html>";
jLabel1.setText(htmtString);
Actually it display the blue color link on the label. But I can't click and go the site. How can I do it.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Mar 26th, 2008, 09:13 AM
#2
Re: Clickable link to get the browser in a JLable
Code:
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import javax.swing.JLabel;
public class Util {
public static void main(String[] args) {
JLabel lbl = new JLabel();
lbl.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
try {
Runtime.getRuntime().exec("http://www.java.sun.com");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Mar 26th, 2008, 09:02 PM
#3
Thread Starter
PowerPoster
Re: Clickable link to get the browser in a JLable
Thanks for the replay.
Actually I got a runtime exception,
java.io.IOException: Cannot run program "http://www.java.sun.com": CreateProcess error=2, The system cannot find the file specified
Do you have any idea why it is happened.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Mar 27th, 2008, 01:53 AM
#4
Re: Clickable link to get the browser in a JLable
If you're using windows then the default browser should start and navigate to java.sun.com anyway.
I've attached a class called BrowserLauncher. This class is ready to use, it starts the default browser for Windows, Mac & Linux (Unless you're using FluxBox).
Attached Files
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Apr 8th, 2008, 10:31 PM
#5
Thread Starter
PowerPoster
Re: Clickable link to get the browser in a JLable
Thanks a lot pal. At the time I just write a code only working for Windows. Working with dlls. I'll look at your code and try to make it compatible with all OS such as Linux, Mac and so.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Apr 8th, 2008, 10:51 PM
#6
Re: Clickable link to get the browser in a JLable
My code is compatible with all OSs
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Apr 8th, 2008, 11:02 PM
#7
Thread Starter
PowerPoster
Re: [RESOLVED] Clickable link to get the browser in a JLable
Yes pal, it is. What I say is, I want to look at my code with your one and check how about my attempt. Your code exactly same what I want
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Apr 8th, 2008, 11:32 PM
#8
Re: [RESOLVED] Clickable link to get the browser in a JLable
Originally Posted by
eranga262154
Yes pal, it is. What I say is, I want to look at my code with your one and check how about my attempt. Your code exactly same what I want
lol
sorry for the misunderstanding then
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
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
Click Here to Expand Forum to Full Width