title: Control the dimensions of the JavaFX virtual keyboard
body: <p>Is there any way to resize the JavaFX virtual keyboard subwindow?</p>
  
  <p>I refer to the stage that the virtual keyboard belongs to as a subwindow because of how it is labeled in Scenic View.</p>
  
  <p>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:
  <a href="https://i.imgur.com/KP65dlM.png" rel="nofollow noreferrer">http://i.imgur.com/KP65dlM.png</a></p>
  
  <p>Applying this styling gets me a somewhat desired button height: </p>
  
  <pre><code>.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; 
  </code></pre>
  
  <p>The problem, seen here <a href="https://i.imgur.com/x5R7feQ.png" rel="nofollow noreferrer">http://i.imgur.com/x5R7feQ.png</a>, is that the subwindow that contains the virtual keyboard needs to be taller to display the resized buttons. </p>
  
  <p>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:</p>
  
  <pre><code>public static PopupWindow getKeyboard() {
  
      @SuppressWarnings("deprecation")
      final Iterator&lt;Window&gt; windows = Window.impl_getWindows();
  
      while (windows.hasNext()) {
          final Window window = windows.next();
          if (window instanceof PopupWindow) {
              if (window.getScene() != null &amp;&amp; window.getScene().getRoot() != null) {
                  Parent root = window.getScene().getRoot();
                  if (root.getChildrenUnmodifiable().size() &gt; 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;
  }
  </code></pre>
  
  <p>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.</p>
  
  <p><img src="https://i.stack.imgur.com/zIfPl.png" alt="enter image description here"></p>