如何在显示虚拟键盘之前将其置于底部 - javafx

时间:2018-01-29 17:33:49

标签: javafx virtual-keyboard

如何将键盘置于屏幕底部? 电路板已经显示后,我只有键盘/ PopupWindow的大小。在调用show()之前,每个函数都返回0.0以获得所请求的宽度。如果我之前知道宽度,我可以正确设置位置。 键盘大小可能会在以后更改,这就是我无法使用设置大小进行操作的原因。 我正在使用fx-onscreen-keyboard

我的小服务:

public class KeyboardService {

private double screenWidth = Screen.getPrimary().getVisualBounds().getWidth();
private double screenHight = Screen.getPrimary().getVisualBounds().getHeight();
private double keyboardPosX = 0.0;
private double keyboardPosY = 0.0; 

private KeyBoardPopup keyboardPopup;

public KeyboardService() {
    keyboardPopup = KeyBoardPopupBuilder.create().initLocale(Locale.GERMAN).build();
    keyboardPopup.setAutoHide(true);
    keyboardPopup.setConsumeAutoHidingEvents(false);
    keyboardPopup.getKeyBoard().setScale(2.5);
    keyboardPopup.getKeyBoard().setLayer(DefaultLayer.DEFAULT);

    keyboardPopup.getKeyBoard().setOnKeyboardCloseButton((e) -> {
        keyboardPopup.hide();
    });

}

public void showKeyboard(Node node){
    keyboardPosX = (screenWidth - keyboardPopup.getWidth())/2;
    //keyboardPosX = (screenWidth - keyboardPopup.getKeyBoard().getWidth())/2;
    keyboardPosY = screenHight;
    keyboardPopup.show(node, keyboardPosX, keyboardPosY);
}}

1 个答案:

答案 0 :(得分:1)

键盘的宽度是在布置了弹出窗口的弹出窗口时定义的,当你调用show后会发生什么。

执行此操作的简单方法是收听widthProperty的{​​{1}},获取新值,然后相应地移动弹出窗口。

这样做:

KeyBoardPopup