Z P
Z P

Reputation: 19

How can I access a correct version of a Java Desktop class

I have a JavaFX application that can be used to edit files of a particular type on Windows OS. By using launch4j-maven-plugin I can make an exe file, and by using Inno Setup I can make an installer of this application that has a particular file type associated to it (kb files). If I install the application and double click on the file that this application is associated to while the application is not open already, the application opens and I can read the said file (I read main function args and use the filename to read the file). The problem I have is if the user tries to double click the file that this application is associated to, while the application is running. That does not work. At another answers I found out that by using Desktop.setOpenFileHandler(...) I can set the open file handler that will handle this event. However, my version of Desktop does not have this option, it only has options to open, edit, print, mail or browse a file as can be seen from the allowed actions that are part of the Desktop class that I can access:

    public static enum Action {
        /**
         * Represents an "open" action.
         * @see Desktop#open(java.io.File)
         */
        OPEN,
        /**
         * Represents an "edit" action.
         * @see Desktop#edit(java.io.File)
         */
        EDIT,
        /**
         * Represents a "print" action.
         * @see Desktop#print(java.io.File)
         */
        PRINT,
        /**
         * Represents a "mail" action.
         * @see Desktop#mail()
         * @see Desktop#mail(java.net.URI)
         */
        MAIL,
        /**
         * Represents a "browse" action.
         * @see Desktop#browse(java.net.URI)
         */
        BROWSE
    };

So my question is how can I get to the correct version of a Desktop class (my jre is jre 1.8.0_351). And if that is not possible, can anyone propose another method for handling the event of opening a file by double clicking on it in Windows?

I first had Java 1.8.0_202, I updated to 1.8.0_351 to try to solve the problem, but that did not help. I also tried to use the Application class to set event handler:

 Application lowLevelApp = Application.GetApplication();
 MyEventHandler eventhandler = new MyEventHandler(lowLevelApp);
 eventhandler.setOpenFilesHandler(new MyHandleOpenFilesEvent());
 lowLevelApp.setEventHandler(eventhandler);

but that did not work either.

Upvotes: 0

Views: 142

Answers (1)

mipa
mipa

Reputation: 10640

Just by looking at the documentation of that method https://docs.oracle.com/javase/9/docs/api/java/awt/desktop/OpenFilesHandler.html you would see that this method was introduced in version 9 of Java. At the moment we are at version 19 so it is quite likely that some API between your 8 und the current 19 have changed. Just upgrade your Java and JavaFX and everything will be good.

Upvotes: 1

Related Questions