public class JLabelHyperlinkHandler
extends java.lang.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();
}
}
});
| Constructor and Description |
|---|
JLabelHyperlinkHandler() |
JLabelHyperlinkHandler(javax.swing.JLabel label,
java.awt.event.ActionListener l) |
| Modifier and Type | Method and Description |
|---|---|
void |
addActionListener(java.awt.event.ActionListener l) |
javax.swing.JLabel |
getLabel() |
void |
removeActionListener(java.awt.event.ActionListener l) |
void |
setLabel(javax.swing.JLabel newValue) |