My requirement is to have a button that opens a given pdf file or directory available on the filesystem using the platform default application (i,e, Explorer/Nautilus/etc for the directories and AcrobatReader/Evince/etc for the pdf file).
I'm not sure what's the JavaFX best practice to fulfil this requirement but my understanding is that the following code, even though an awt api, should work:
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(FILE);
}
There are 2 issues here:
1. Is this supposed to work when called from the FX thread? According toRT-31468 it shouldn't, but then it's used in the official documentation http://docs.oracle.com/javafx/2/ui_controls/file-chooser.htm suggesting it should work
2. If it is supposed to work thenRT-31468 is a valid bug, tested on Ubuntu 12.10 and 13.10, the jvm freezes. Everything works on Windows 7.
A workaround suggested on the support forum is to use HostServices.showDocument which again works perfectly on Windows but on Ubuntu opens every file or directory using the default browser (Firefox in my case)
To summarize I think what should be addressed is:
1. Have Desktop.open and HostServices.showDocument to work consistently across multiple operating systems.
2. Have some official documentation showing the JavaFX way to fulfil the "open a file/directory using the default viewer/application" requirement which I think is quite common for a desktop application.
I'm not sure what's the JavaFX best practice to fulfil this requirement but my understanding is that the following code, even though an awt api, should work:
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(FILE);
}
There are 2 issues here:
1. Is this supposed to work when called from the FX thread? According to
2. If it is supposed to work then
A workaround suggested on the support forum is to use HostServices.showDocument which again works perfectly on Windows but on Ubuntu opens every file or directory using the default browser (Firefox in my case)
To summarize I think what should be addressed is:
1. Have Desktop.open and HostServices.showDocument to work consistently across multiple operating systems.
2. Have some official documentation showing the JavaFX way to fulfil the "open a file/directory using the default viewer/application" requirement which I think is quite common for a desktop application.
- duplicates
-
JDK-8123117 desktop.open() method of Desktop class doesn't work on Linux
- Closed
-
JDK-8195086 Using the Desktop.open() method from a JavaFX application hangs the application. It works from a Java application
- Closed