1 package net.sf.openrocket.gui.components;
3 import java.awt.Desktop;
4 import java.awt.event.MouseAdapter;
5 import java.awt.event.MouseEvent;
6 import java.io.IOException;
8 import java.net.URISyntaxException;
10 import javax.swing.JLabel;
13 * A label of a URL that is clickable. Clicking the URL will launch the URL in
14 * the default browser if the Desktop class is supported.
16 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
18 public class URLLabel extends JLabel {
20 private final String url;
22 public URLLabel(String urlLabel) {
28 if (Desktop.isDesktopSupported()) {
30 setText("<html><a href=\"" + url + "\">" + url + "</a>");
32 this.addMouseListener(new MouseAdapter() {
34 public void mouseClicked(MouseEvent e) {
35 Desktop d = Desktop.getDesktop();
37 d.browse(new URI(url));
38 } catch (URISyntaxException e1) {
39 throw new RuntimeException("BUG: Illegal URL: " + url, e1);
40 } catch (IOException e1) {
41 System.err.println("Unable to launch browser:");