0

I'm developing a javafx app for an embledded system. (WIN 7 EMB, JAVA 8)

this system is touch (no keyboard) but JVM does not set by default virtual keyboard

how can i set once and definitively this arguments on JVM ?

-Dcom.sun.javafx.isEmbedded=true
-Dcom.sun.javafx.touch=true
-Dcom.sun.javafx.virtualKeyboard=javafx

thanks for help!

ntalbs
  • 28,700
  • 8
  • 66
  • 83
  • See: https://stackoverflow.com/questions/1754077/setting-jvm-parameters-at-runtime – Itai Jul 02 '18 at 13:38
  • Ty mate... but i've done a search before post.... this solution does not work! i will problably solve this using an external launcher... – Fabrizio Scarponi Jul 03 '18 at 07:37
  • Can you confirm the main method is indeed being called? IIRC in some cases the JVM may skip the `main` method if the main class extends `Application`. See e.g. https://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm (last bullet before fig. 3-1) and https://docs.oracle.com/javase/9/tools/java.htm#JSWOR624 (under "Description") – Itai Jul 03 '18 at 08:07
  • Confirmed, i found the solution by wrapping my main, i will post the solution by myself – Fabrizio Scarponi Jul 03 '18 at 08:14
  • it's a fake, already found solution works well from IDE (eclipse) but not from jar executable – Fabrizio Scarponi Jul 03 '18 at 10:42

2 Answers2

4

JavaFX doesn't initialize until Application.launch(...) is called. You should try to set system properties, for example, in your main(String[] args) method:

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", "true");
    launch(args); // launch JavaFX
}
turikhay
  • 298
  • 2
  • 8
  • Hi turikhay, sry but don't work on java 8, i'm not sure but i think cause jvm need this params BEFORE start the main..... this is my main -> it dont work 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", "true"); launch(args); } – Fabrizio Scarponi Jul 03 '18 at 07:32
  • It has! just i need 2 main for let it work good... one for start the sencond main after set the JVM settings – Fabrizio Scarponi Jul 09 '18 at 07:38
0

At last, i've found a similar solution, wrapping my main in another one that set jvm prop before launching my original main

 package launcher;

import application.Main;

public class myLauncher {

    public static void main(String[] args) {


        Main.main(null);

    }

}

and this is the main

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);
            }

(is necessary to flag->"Extract required libs in generated jar" on jar exportation for work!)

I'm sorry but i dont have a clear explanation for this solution!

  • Is there really a need to find the method via reflection? Seems overly complex and error-prone, especially since the class is hard-coded. Why not just call `application.Main.main(arguments)`? – Itai Jul 03 '18 at 08:57
  • This is a good idea, in any case i've another problem... virtual keyboard starts well by IDE but not from jar.... this is frustrating... – Fabrizio Scarponi Jul 03 '18 at 10:40
  • Another update: after start app via prompt i've intercetted this exception-->images/vk-light.png Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Image cannot be null --> seems like dont find an image for virtual keyboard – Fabrizio Scarponi Jul 03 '18 at 11:07
  • Finally, whit the flag "Extract required libs in generated jar" it works! i will spend 1 more day for test and will refactor this post... i think that jvm got problem to resolve uri of Virtual Keyboard imgs (but i'm not sure) – Fabrizio Scarponi Jul 03 '18 at 11:18