0

I was writing java FX application. I have two monitors connected into one PC. I wanted to open application in the second window monitor. somehow I managed to do it with vbox not loading inside of them components. But when I try to load my fxml view into Parent it dosn't react at all. I was reviev following stackoverflow answer `

Choose which monitor does a JavaFX window open in

But when you will try to load fxml view it dosn't react why ? How I can make it work?. here is my code

@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();
}

`

Jahongir Sabirov
  • 460
  • 1
  • 8
  • 24

1 Answers1

0

I found it it's answer with following code

    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();
Jahongir Sabirov
  • 460
  • 1
  • 8
  • 24