javafx以编程方式设置虚拟键盘的参数 [英] javafx programmatically set arguments for virtual keyboard

查看:295
本文介绍了javafx以编程方式设置虚拟键盘的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个桌面应用程序,将在没有键盘的计算机上使用,输入将在触摸屏上。从eclipse运行时,我可以让虚拟键盘显示在文本字段上。我使用了这些参数

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

以下链接显示我在哪里添加参数。
如何添加命令在Eclipse中运行java代码时的行参数?

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

当我创建一个可运行的jar文件时,键盘不显示。我正在寻找一种以编程方式设置这些参数的方法,以便runnable jar文件将在任何计算机上显示虚拟键盘。任何帮助将不胜感激。

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.

推荐答案

我能找到的唯一可行解决方案来自这里
javafx应用程序的Gradle构建:由于缺少系统属性,虚拟键盘无法正常工作

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

在调用应用程序原始main方法之前创建一个包装类并设置系统属性。

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

制作runnable jar文件时只需指向MainWrapper启动配置的类。

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

这篇关于javafx以编程方式设置虚拟键盘的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆