Reputation: 23
Is there any way to resize the JavaFX virtual keyboard subwindow?
I refer to the stage that the virtual keyboard belongs to as a subwindow because of how it is labeled in Scenic View.
I am developing an application that is going to exclusively use the virtual keyboard for text input on a surface 3 tablet. The keyboard's buttons are too short to reliably press on the surface's screen due to the resolution (2160x1440) as seen here, resized to a width of 1920: https://i.sstatic.net/7yomw.png
Applying this styling gets me a somewhat desired button height:
.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;
The problem, seen here https://i.sstatic.net/DcZgu.png, is that the subwindow that contains the virtual keyboard needs to be taller to display the resized buttons.
I have a method to return the reference to the virtual keyboard so I can set a listener in other controllers to hide the VK when it loses focus. I try to resize the VK but I cannot get control of the attributes of the subwindow:
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;
}
The team I'm working with cannot build a custom virtual keyboard for the application at the moment due to time contstraints but it is likely the route we'll go in the future.
Upvotes: 2
Views: 1547
Reputation: 45476
You are almost there.
If you change the height of the keyboard within getPopupWindow()
:
if(popup.lookup(".fxvk")!=null){
FXVK vk = (FXVK)popup.lookup(".fxvk");
vk.setMinHeight(400);
return (PopupWindow)window;
}
Once you have the instance of the popup window, just call setAutoFix(true)
:
PopupWindow keyboard=getPopupWindow();
keyboard.setAutoFix(true);
Upvotes: 2