2017-06-15 6 views
0

私の開発システムには、3つのディスプレイが接続されたWindows PCが含まれています。 3番目のディスプレイは私のタッチスクリーンディスプレイです。私は、コントロールパネルから "タブレットPCの設定"でタッチスクリーンディスプレイとしてこの画面を使用するようにWindowsに指示しました。JavaFX仮想キーボードの表示の変更

私のアプリケーションは、TextFieldを含むシンプルなJavaFXタッチスクリーンアプリケーションです。

  • -Dcom.sun.javafx.isEmbedded =真
  • -Dcom.sun.javafx.touch =真
  • -Dcom:私はtrueに以下の設定を設定した仮想キーボードを表示するには。 sun.javafx.virtualKeyboard = javafx

私の問題は、キーボードが表示されているが、間違ったモニタに表示されることです。これは、タッチモニタに設定されている第3のモニタの代わりに、プライマリモニタに表示されます。

現在のシステム構成でタッチモニターに仮想キーボードを表示する方法はありますか?たとえば、所有者アプリケーションがどこにあるのかをキーボードに伝えることによって、正しいモニタに表示されますか?

答えて

0

キーボードが表示されているモニタを、アプリケーションが表示されているモニタに変更する方法を確認しました。

textFieldのフォーカスされたプロパティに変更リスナーをアタッチします。変更リスナーを実行するときは、キーボードポップアップを取得します。次に、アプリケーションが表示されているモニタのアクティブな画面境界を見つけて、キーボードのx座標をこの位置に移動します。

autoFixをtrueに設定すると、キーボードはモニタの外側に(部分的に)存在しないことを確認します。autoFixはy座標を自動的に調整します。 autoFixを設定しない場合は、y座標を手動で設定する必要もあります。

@FXML 
private void initialize() { 
    textField.focusedProperty().addListener(getKeyboardChangeListener()); 
} 

private ChangeListener getKeyboardChangeListener() { 
    return new ChangeListener() { 
     @Override 
     public void changed(ObservableValue observable, Object oldValue, Object newValue) { 
      PopupWindow keyboard = getKeyboardPopup(); 

      // Make sure the keyboard is shown at the screen where the application is already shown. 
      Rectangle2D screenBounds = getActiveScreenBounds(); 
      keyboard.setX(screenBounds.getMinX()); 
      keyboard.setAutoFix(true); 
     } 
    }; 
} 

private PopupWindow getKeyboardPopup() { 
    @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) { 
         return (PopupWindow)window; 
        } 
       } 
      } 
      return null; 
     } 
    } 
    return null; 
} 

private Rectangle2D getActiveScreenBounds() { 
    Scene scene = usernameField.getScene(); 
    List<Screen> interScreens = Screen.getScreensForRectangle(scene.getWindow().getX(), scene.getWindow().getY(), 
      scene.getWindow().getWidth(), scene.getWindow().getHeight()); 
    Screen activeScreen = interScreens.get(0); 
    return activeScreen.getBounds(); 
} 
関連する問題