0

I have a desktop application that will be used on computers with no keyboard, input will be on a touch screen. I can get the virtual keyboard to show up on textfields fine when running from eclipse. I used these arguments

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

The following link shows me where to add the arguments. how to add command line parameters when running java code in Eclipse?

When I make a runnable jar file the keyboard does not show up. I am looking for a way to set these arguments programmatically so that the runnable jar file will display the virtual keyboard on any computer. Any help will be greatly appreciated.

Community
  • 1
  • 1
Colm O S
  • 110
  • 1
  • 8

2 Answers2

2

The only working solution I could find came from here Gradle build for javafx application: Virtual Keyboard is not working due to missing System property

Create a wrapper class and set the system properties before invoking the applications original main method.

public class MainWrapper {

    public static void main(String[] args) throws Exception 
    {  // application - package name
        Class<?> app = Class.forName("application.Main");         
        Method main = app.getDeclaredMethod("main", String[].class);     
        System.setProperty("com.sun.javafx.isEmbedded", "true"); 
        System.setProperty("com.sun.javafx.touch", "true");          
        System.setProperty("com.sun.javafx.virtualKeyboard", "javafx");     
        Object[] arguments = new Object[]{args};
        main.invoke(null, arguments);
    }
}

When making the runnable jar file just point to the MainWrapper class for the launch configuration.

Community
  • 1
  • 1
Colm O S
  • 110
  • 1
  • 8
1

The -D option to the JVM sets a system property. So you can achieve the same by doing the following:

public class MyApplication extends Application {

    @Override
    public void init() {
        System.setProperty("com.sun.javafx.touch", "true");         
        System.setProperty("com.sun.javafx.isEmbedded", "true");        
        System.setProperty("com.sun.javafx.virtualKeyboard", "none");
    }

    @Override
    public void start(Stage primaryStage) {
        // ...
    }
}
James_D
  • 201,275
  • 16
  • 291
  • 322
  • Hi, I tried that already but it never worked for me. Im not sure but the arguments dont take effect before the application runs maybe. I found a working solution just now though.. It may be a work around, Create another class, a wrapper class that will set those arguments and then launch the main class. http://stackoverflow.com/questions/32373313/gradle-build-for-javafx-application-virtual-keyboard-is-not-working-due-to-miss – Colm O S Aug 03 '16 at 10:48
  • Thanks for the fast reply though. – Colm O S Aug 03 '16 at 10:53