【问题标题】:Control the dimensions of the JavaFX virtual keyboard控制 JavaFX 虚拟键盘的尺寸
【发布时间】:2015-05-18 14:21:51
【问题描述】:

有没有办法调整 JavaFX 虚拟键盘子窗口的大小?

我将虚拟键盘所属的阶段称为子窗口,因为它在 Scenic View 中是如何标记的。

我正在开发一个应用程序,它将专门使用虚拟键盘在 Surface 3 平板电脑上进行文本输入。由于分辨率 (2160x1440) 如下所示,键盘的按钮太短而无法可靠地按下表面屏幕,宽度调整为 1920: http://i.imgur.com/KP65dlM.png

应用这种样式让我得到了一些想要的按钮高度:

.fxvk {
-fx-cursor: default;
-fx-background-color: linear-gradient(to bottom, rgb(126, 126, 126) 0%, rgb(76, 76, 76) 10%, rgb(84, 84, 84) 100%);
-fx-background-insets: 0,0,0,0;
-fx-padding: 8 4 10 4;
-fx-min-height: 400; 

问题,在这里看到http://i.imgur.com/x5R7feQ.png,是包含虚拟键盘的子窗口需要更高才能显示调整大小的按钮。

我有一个方法可以返回对虚拟键盘的引用,这样我就可以在其他控制器中设置一个侦听器,以便在 VK 失去焦点时隐藏它。我尝试调整 VK 的大小,但无法控制子窗口的属性:

public static PopupWindow getKeyboard() {

    @SuppressWarnings("deprecation")
    final Iterator<Window> windows = Window.impl_getWindows();

    while (windows.hasNext()) {
        final Window window = windows.next();
        if (window instanceof PopupWindow) {
            if (window.getScene() != null && window.getScene().getRoot() != null) {
                Parent root = window.getScene().getRoot();
                if (root.getChildrenUnmodifiable().size() > 0) {
                    Node popup = root.getChildrenUnmodifiable().get(0);
                    if (popup.lookup(".fxvk") != null) {
                        if (popup instanceof FXVK) {

                            FXVK keyboard = (FXVK) popup; // reference to the vk skin

                            keyboard.getScene().heightProperty().add(200); // This increases the height but the vk window does not size to its contents like other windows

                            PopupWindow test = (PopupWindow) window; // reference to the window with the vk, casted to a PopupWindow
                            test.getOwnerWindow().setHeight(test.getOwnerWindow().getHeight() + 200); // This increases the height but the vk window does not size to its contents like other windows

                            return test;
                        }
                    }
                }
            }
            return null;
        }
    }
    return null;
}

由于时间限制,我正在与之合作的团队目前无法为应用程序构建自定义虚拟键盘​​,但这很可能是我们将来会走的路线。

【问题讨论】:

    标签: javafx windows-8.1 javafx-8 virtual-keyboard


    【解决方案1】:

    你快到了。

    如果在getPopupWindow()内改变键盘高度:

        if(popup.lookup(".fxvk")!=null){
            FXVK vk = (FXVK)popup.lookup(".fxvk");
            vk.setMinHeight(400);
            return (PopupWindow)window;
        }
    

    一旦你有了弹出窗口的实例,只需调用setAutoFix(true)

    PopupWindow keyboard=getPopupWindow();
    keyboard.setAutoFix(true);
    

    【讨论】:

      猜你喜欢
      • 2015-01-02
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      • 2015-01-02
      • 2015-03-14
      • 1970-01-01
      • 2011-02-14
      • 2019-06-06
      相关资源
      最近更新 更多