[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.
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();
}
}
});
}
}
Re: Clickable link to get the browser in a JLable
Thanks for the replay.
Actually I got a runtime exception,
Quote:
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.
1 Attachment(s)
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).
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.
Re: Clickable link to get the browser in a JLable
My code is compatible with all OSs
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 :)
Re: [RESOLVED] Clickable link to get the browser in a JLable
Quote:
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