我的开发系统包含一台Windows pc,上面有三个显示器。第三个显示器是我的触摸屏显示器。我已经指示Windows使用这个屏幕作为我的触摸屏显示与“平板电脑设置”从控制面板。
我的应用程序是一个简单的JavaFX触摸屏应用程序,包含一个TextField。为了显示虚拟键盘,我将以下设置设置为true:
我的问题是键盘出现了,但出现在了错误的显示器上。它显示在主监视器上,而不是设置为触摸监视器的第三个监视器上。
在当前的系统配置中,是否有方法在我的触摸监视器上显示虚拟键盘?例如,通过告诉键盘的所有者应用程序在哪里,所以它会显示在正确的监视器上吗?
发布于 2017-06-19 12:37:09
了解如何将显示键盘的监视器更改为显示应用程序的监视器。
将更改侦听器附加到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();
}https://stackoverflow.com/questions/44562933
复制相似问题