Maven dependeny :
<!-- onscreen-keyboard -->
<dependency>
<groupId>org.comtel2000</groupId>
<artifactId>fx-onscreen-keyboard</artifactId>
<version>8.2.5</version>
</dependency>
<!-- onscreen-keyboard -->
Static function showVirtualKeyboard :
public static void showVirtualKeyboard(Stage primaryStage){
Platform.runLater(() -> {
if(keyBoardPopup == null){
KeyboardPane kb = new KeyboardPane();
kb.setLayer(DefaultLayer.NUMBLOCK);
try {
kb.load();
} catch (Exception e) {
}
keyBoardPopup = new KeyBoardPopup(kb);
Scene scene = new Scene(new Group(), 0.1, 0.1);
Stage stage = new Stage();
stage.initOwner(primaryStage);
//stage.initStyle(StageStyle.UTILITY);
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(scene);
//stage.initModality(Modality.APPLICATION_MODAL);
stage.setAlwaysOnTop(true);
keyBoardPopup.show(stage);
keyBoardPopup.registerScene(primaryStage.getScene());
keyBoardPopup.setVisible(true);
kb.setOnKeyboardCloseButton(event -> keyBoardPopup.setVisible(false));
String key = "virtualkeyboard";
double scale = Options.getScale(key);
double x = Options.getWindowX(key);
double y = Options.getWindowY(key);
boolean inBounds = true;
if(x != 0 && y != 0 && y > 0){
ObservableList<Screen> screenSizes = Screen.getScreens();
if(screenSizes.size() == 1){
if(x >= screenSizes.get(0).getBounds().getMaxX() || y >= screenSizes.get(0).getBounds().getMaxY()){
inBounds = false;
}
}
if(inBounds){
keyBoardPopup.setX(x);
keyBoardPopup.setY(y);
}
}
ChangeListener<Number> changeListenerX = null, changeListenerY = null;
changeListenerX = (observable, oldValue, newValue) -> Options.setWindowX(key, newValue.doubleValue());
changeListenerY = (observable, oldValue, newValue) -> Options.setWindowY(key, newValue.doubleValue());
keyBoardPopup.xProperty().addListener(changeListenerX);
keyBoardPopup.yProperty().addListener(changeListenerY);
kb.setScale(scale < 0 ? 2 : scale);
//Options.setScale(key, -1);
kb.scaleProperty().addListener((observable, oldValue, newValue) -> Options.setScale(key, newValue.doubleValue()));
}else{
keyBoardPopup.setVisible(true);
}
});
}
Some Options functions
private static Preferences preferences = Preferences.userRoot();
public static Preferences getPreferences() { try { preferences.sync(); } catch (Exception e) { } return preferences; }
public synchronized static double getWindowX(String window) {
return getPreferences()
.getDouble(ApplicationName + ".system.window." + window + ".x", 0);
}
public synchronized static void setWindowX(String window, double x) {
getPreferences().putDouble(ApplicationName + ".system.window." + window + ".x", x);
}
public synchronized static double getWindowY(String window) {
return getPreferences()
.getDouble(ApplicationName + ".system.window." + window + ".y", 0);
}
public synchronized static void setWindowY(String window, double y) {
getPreferences().putDouble(ApplicationName + ".system.window." + window + ".y", y);
}
public synchronized static double getScale(String window) {
return getPreferences()
.getDouble(ApplicationName + ".system.scale." + window + ".x", -1);
}
public synchronized static void setScale(String window, double x) {
getPreferences().putDouble(ApplicationName + ".system.scale." + window + ".x", x);
}