Reputation: 115
We are using more than one stage(window) in JavaFX for a desktop standalone application. So when we drag or move any of the stage(window) form one point to another and clicking a certain button to navigate to the other page means the new stage is coming to center again(default position). Is there any methods to set the future stage(future windows) also in the previous stage location or point(previous windows). Please help.
Upvotes: 1
Views: 325
Reputation: 34518
You can control stage location before showing it. Just remember last stage coordinates and create new one in the same point:
public class FXStages extends Application {
private int counter = 0;
@Override
public void start(final Stage stage) {
Button btn = new Button();
btn.setText("Reopen");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
stage.close();
Stage newStage = new Stage();
newStage.setX(stage.getX());
newStage.setY(stage.getY());
start(newStage);
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
stage.setTitle("Stage " + counter++);
stage.setScene(scene);
stage.show();
}
}
Upvotes: 1