Kann es sein, dass die Desktop-Funktion nicht korrekt funktioniert? Ich habe einen jEditorPane, und darin verlinke ich bestimmte Einträge. Mal URLs, mal E-Mail-Adressen, mal Dateien auf der Festplatte. Der HyperlinkEventListener ruft dann eine Methode auf, um den Link zu öffnen:
URLs und Mailto klappt wunderbar, open für Dateien nur manchmal, meistens nicht. Eine Systematik habe ich noch nicht erkennen können. Beim Debuggen jedesmal genau gesehen, dass die zu öffnende Datei existiert, keine kryptischen Zeichen oder Leerzeichen vorhanden sind, aber nichts tut sich... Auch keine Exception!
Das Problem tritt unter Windows/Mac/Linux auf.
Weiß jemand, woran das liegen könnte?
Java:
/**
* This method opens a file or URL either from within a clicked link
* inside the jEditorPane (see
* {@link #eventHyperlinkActivated(javax.swing.event.HyperlinkEvent)
* eventHyperlinkActivated(javax.swing.event.HyperlinkEvent)}
* or from the attachment-list (see {@link #openAttachment() openAttachment()}.
*
* @param linktype the clicked link as string
* @param linkurl the clicked link as URL
*/
private void openHyperlink(String linktype) {
File linkfile = null;
// check whether we have desktop-support here or not...
if (Desktop.isDesktopSupported()) {
// get the desktop
Desktop desk = Desktop.getDesktop();
// if yes, proceed...
try {
// if the string contains "http://", we assume we have a webpage
if (CCommonMethods.isHyperlink(linktype)) {
... // öffnet Hyperlinks
}
// if the string starts with "mailto:", we assume we have an email-link
else if (linktype.startsWith("mailto:")) {
... // öffnet E-Mail
}
// otherwise try to open the file with the associated application
else {
// create file from the link
// this method returns a valid, absolute file-path to the
// linked file. if the file does not exist,
// this method returns "null".
linkfile = CCommonMethods.getLinkFile(settings,linktype);
// check whether opening a file is supported or not
if (!desk.isSupported(Desktop.Action.OPEN)) {
// display error message box
JOptionPane.showMessageDialog(getFrame(),
getResourceMap().
getString("errLinkUnsopportedMsg"),
getResourceMap().getString("errLinkUnsopportedTitle"),
JOptionPane.ERROR_MESSAGE,
CConstants.iconMsgError);
return;
}
desk.open(linkfile);
}
}
catch (IOException e) {
// display error message box
JOptionPane.showMessageDialog(getFrame(),
getResourceMap().getString("errLinkNotFoundMsg",(linkfile!=null)?
linkfile.toString():
getResourceMap().getString("linkFileUnknown")),
getResourceMap().getString("errLinkNotFoundTitle"),
JOptionPane.ERROR_MESSAGE,
CConstants.iconMsgError);
}
catch (IllegalArgumentException e) {
// display error message box
JOptionPane.showMessageDialog(...);
}
catch (SecurityException e) {
// display error message box
JOptionPane.showMessageDialog(...);
}
catch (UnsupportedOperationException e) {
// display error message box
JOptionPane.showMessageDialog(...);
}
catch (URISyntaxException e) {
// display error message box
JOptionPane.showMessageDialog(...);
}
}
else {
// display error message box
JOptionPane.showMessageDialog(...);
}
}
URLs und Mailto klappt wunderbar, open für Dateien nur manchmal, meistens nicht. Eine Systematik habe ich noch nicht erkennen können. Beim Debuggen jedesmal genau gesehen, dass die zu öffnende Datei existiert, keine kryptischen Zeichen oder Leerzeichen vorhanden sind, aber nichts tut sich... Auch keine Exception!
Das Problem tritt unter Windows/Mac/Linux auf.
Weiß jemand, woran das liegen könnte?
Zuletzt bearbeitet: