[英]JavaFX - Virtual Keyboard Doesn't Show When the App Jar is Generated
我在IntelliJ14.14中創建了一個JavaFX應用程序,它將使用JavaFX虛擬鍵盤 。 我在mainApp類控制器中添加了以下屬性:
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);
}
當我從IntelliJ運行應用程序時,一切正常。 虛擬鍵盤完美運行。
但是當我從Build - > Build Artifacts生成應用程序的Jar文件... - > Build並執行它時,鍵盤永遠不會顯示,因為沒有設置VM選項。
這是我想念的東西......?
提前致謝...
編輯
我找到了一種方法來完成這項工作,使用此命令從cmd運行文件:
java -Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard="javafx" -Dcom.sun.javafx.touch=true -jar myApp.jar
但是我想讓它只是執行Jar文件......
編輯
還有另一種方法來實現我想要的......
在jar的同一文件夾中創建一個.bat文件並放入其中:
start javaw -Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard="javafx" -Dcom.sun.javafx.touch=true -jar myApp.jar
因此,當執行.bat文件並啟動jar文件時,系統屬性會正確加載...
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
//...
//...
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.