控制 JavaFX 虚拟键盘的尺寸
Control the dimensions of the JavaFX virtual keyboard
有什么方法可以调整 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 看到的问题是包含虚拟键盘的子窗口需要更高才能显示调整大小的按钮。
我有一个方法可以 return 引用虚拟键盘,这样我就可以在其他控制器中设置一个侦听器,以便在失去焦点时隐藏 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;
}
由于时间限制,目前与我合作的团队无法为应用程序构建自定义虚拟键盘,但这很可能是我们将来要走的路。
你快到了。
如果在 getPopupWindow()
内更改键盘高度:
if(popup.lookup(".fxvk")!=null){
FXVK vk = (FXVK)popup.lookup(".fxvk");
vk.setMinHeight(400);
return (PopupWindow)window;
}
获得弹出窗口的实例后 window,只需调用 setAutoFix(true)
:
PopupWindow keyboard=getPopupWindow();
keyboard.setAutoFix(true);
有什么方法可以调整 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 看到的问题是包含虚拟键盘的子窗口需要更高才能显示调整大小的按钮。
我有一个方法可以 return 引用虚拟键盘,这样我就可以在其他控制器中设置一个侦听器,以便在失去焦点时隐藏 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;
}
由于时间限制,目前与我合作的团队无法为应用程序构建自定义虚拟键盘,但这很可能是我们将来要走的路。
你快到了。
如果在 getPopupWindow()
内更改键盘高度:
if(popup.lookup(".fxvk")!=null){
FXVK vk = (FXVK)popup.lookup(".fxvk");
vk.setMinHeight(400);
return (PopupWindow)window;
}
获得弹出窗口的实例后 window,只需调用 setAutoFix(true)
:
PopupWindow keyboard=getPopupWindow();
keyboard.setAutoFix(true);