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();
}
}
});
| Constructor and Description |
|---|
JLabelHyperlinkHandler() |
JLabelHyperlinkHandler(JLabel label,
ActionListener l) |
| Modifier and Type | Method and Description |
|---|---|
void |
addActionListener(ActionListener l) |
JLabel |
getLabel() |
void |
removeActionListener(ActionListener l) |
void |
setLabel(JLabel newValue) |
public JLabelHyperlinkHandler()
public JLabelHyperlinkHandler(JLabel label, ActionListener l)
public void setLabel(JLabel newValue)
public JLabel getLabel()
public void addActionListener(ActionListener l)
public void removeActionListener(ActionListener l)
Copyright © 2014. All Rights Reserved.