简体   繁体   中英

JavaFX - Virtual Keyboard Doesn't Show When the App Jar is Generated

I have created a JavaFX application in IntelliJ14.14 that will use the JavaFX Virtual Keyboard . I have add the following properties in the mainApp class controller:

public static void main(String[] args) {
    System.setProperty("com.sun.javafx.isEmbedded", "true");
    System.setProperty("com.sun.javafx.touch", "true");
    System.setProperty("com.sun.javafx.virtualKeyboard", "javafx");
    launch(args);
}

When I run the app from IntelliJ everything works fine. The virtual keyboard works perfectly.

But when I generate the Jar file of the application from Build -> Build Artifacts... -> Build and execute it, the keyboard never shows because the VM options are not being set.

It's something I'm missing...?

Thanks in advance...

EDIT

I have found a way to make this work, running the file from the cmd with this command:

java -Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard="javafx" -Dcom.sun.javafx.touch=true -jar myApp.jar 

However I want to make this just executing the Jar file...

EDIT

There is another nearby way to accomplish what I want...

Create a file .bat in the same folder of the jar and put in it:

start javaw -Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard="javafx" -Dcom.sun.javafx.touch=true -jar myApp.jar 

So when tha .bat file is executed and the jar file is started, the system properties are loaded correctly...

public class MyApp {  
    public static void main(String[] args) {  

        if (args.length == 0) {  
            try {  
                // re-launch the app itselft with VM option passed  
                Runtime.getRuntime().exec(new String[] {"java", "-Dcom.sun.javafx.isEmbedded=true", "-Dcom.sun.javafx.virtualKeyboard=\"javafx\"", "-Dcom.sun.javafx.touch=true", "-jar", "myApp.jar"});  
            } catch (IOException ioe) {  
                ioe.printStackTrace();  
            }  
            System.exit(0);  
        }  

        // Run the main program with the VM option set  
        //...  
        //...  
    }  
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM