gpt4 book ai didi

java - 将应用程序移至 javafx 中的第二个窗口监视器

转载 作者:行者123 更新时间:2023-12-02 08:19:15 25 4
gpt4 key购买 nike

我正在编写 java FX 应用程序。我有两台显示器连接到一台电脑。我想在第二个窗口监视器中打开应用程序。不知怎的,我设法用 vbox 来做到这一点,而不是在它们的组件内部加载。但是当我尝试将我的 fxml View 加载到 Parent 时,它根本没有反应。我正在回顾 stackoverflow 的答案`

Choose which monitor does a JavaFX window open in

但是当您尝试加载 fxml View 时它没有反应,为什么?我怎样才能让它发挥作用?这是我的代码

@Override
public void start(Stage primaryStage) throws Exception
{
AnchorPane root = FXMLLoader.load(getClass().getClassLoader().getResource("order_state_modal.fxml"));
primaryStage.setTitle("Jasmin");
Scene scene = new Scene(root);
int ind = 1;
for(Screen screen : Screen.getScreens())
{
Rectangle2D bounds = screen.getVisualBounds();
if(ind == 2)
{
primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMaxY());
}
ind ++;
}

primaryStage.setMaximized(true);
primaryStage.setScene(scene);
primaryStage.show();
}

`

最佳答案

我发现它的答案是以下代码

    AnchorPane root = new AnchorPane();
Scene scene = new Scene(root);
int index = 1;
for (Screen screen : Screen.getScreens()) {
Rectangle2D bounds = screen.getVisualBounds();

if(index == 2)
{
primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMinY());
}
index ++;
}
root.getChildren().add(FXMLLoader.load(getClass().getClassLoader().getResource("order_state_modal.fxml")));
primaryStage.setMaximized(true);
primaryStage.setScene(scene);
primaryStage.show();

关于java - 将应用程序移至 javafx 中的第二个窗口监视器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56020527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com