Re: Trying to produce a valid URL for both Windows and Unix - help
Andrew Thompson wrote:
phillip.s.powell@gmail.com wrote:
..
Your new icon can be found <a
href="file:/C:/Documents%20and%20Settings/me/stave.ico>here</a>
That was still not clickable, however, when I tried to click onto the
"link" from within the JLabel within the JFrame.
Two approaches to making a clickable link are
1) implement an HyperLinkListener in a JEditorPane
<http://java.sun.com/developer/onlineTraining/GUI/Swing1/shortcourse.html#JFCEditorPane>
AFAIR it can open an image directly from an HTML link.
That is what I tried to do:
private JEditorPane createHyperlinkPane(String iconPathInfo) {
JEditorPane pane = new JEditorPane();
pane.setBackground(UIManager.getColor("control"));
pane.setOpaque(true);
pane.setEditorKit(new HTMLEditorKit());
pane.setFont(IconMaker.font);
pane.setText(iconPathInfo);
pane.setContentType("text/html");
pane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (evt.getEventType() ==
HyperlinkEvent.EventType.ACTIVATED) {
System.out.println("you clicked!");
}
}
});
return pane;
}
private String createIconPathInfoText() {
StringBuffer sb = new StringBuffer();
sb.append("Your new icon can be found ");
try {
generateIconFilePath();
sb.append("<a href=\"" + getIconFilePath() +
"\">here</a>");
} catch (Exception e) {
sb.append("at: \"" + System.getProperty("user.home") +
File.separator +
this.getIconFileName() + "\"");
}
String iconPathInfo = sb.toString();
System.out.println(iconPathInfo);
return iconPathInfo;
}
However, the link is still not clickable in spite of the setup via
HyperlinkListener
2) add a MouseListener to the JLabel - the
changing of color for hover and active have to
be separately handled, though.
Sorry I meant JEditorPane, not JLabel
Andrew T.