Class JLabelHyperlinkHandler

java.lang.Object
org.monte.media.swing.JLabelHyperlinkHandler

public class JLabelHyperlinkHandler extends Object
JLabelHyperlinkHandler makes HTML hyperlinks in a JLabel clickable.

You can add an action listener to this handler to perform the desired action. The command contains the content of the href attribute in the hyperlink.

Example:

 File f=new File(System.getProperty("user.home"));
 JLabel l=new JLabel("<html>Click this <a href="\""+
                      f.toURI();+
                      "\"">link</a> to open your home folder.");
 new JLabelHyperlinkHandler(l, new ActionListener() {
      public void ActionPerformed(ActionEvent evt) {
              try {
                  File f = new File(new URI(e.getActionCommand()));
                  Desktop.getDesktop().open(f);
              } catch (URISyntaxException ex) {
                  ex.printStackTrace();
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
      }
 });
 
Author:
Werner Randelshofer
  • Constructor Details

    • JLabelHyperlinkHandler

      public JLabelHyperlinkHandler()
    • JLabelHyperlinkHandler

      public JLabelHyperlinkHandler(JLabel label, ActionListener l)
  • Method Details

    • setLabel

      public void setLabel(JLabel newValue)
    • getLabel

      public JLabel getLabel()
    • addActionListener

      public void addActionListener(ActionListener l)
    • removeActionListener

      public void removeActionListener(ActionListener l)