Nosmer
Nosmer

Reputation: 15

How do I manage multiple windows with javafx

Im working on an application that is using multiple windows, I have a button with a handle method:

private class btnHandler implements EventHandler<ActionEvent>{
    @Override
    public void handle(ActionEvent event) {                       
        final BorderPane pane = new BorderPane();

        final Scene scene = new Scene(pane, 600, 400);
        final URL stylesheet = getClass().getResource("playerStyle.css");
        scene.getStylesheets().add(stylesheet.toString());
        Stage window = new Stage();

        eqButton.disableProperty().bind(window.showingProperty());

        window.getIcons().add(new Image(icon.toString()));
        window.setScene(scene);
        window.setResizable(false);
        window.setTitle("Title");
        window.show();
    }              
}

and it works just fine, but - creates a new window right on top of the first one. So i would like to ask - is there a way to make it appear somewhere else? I want to make it always appear at the side of a first window, regardless of its position - how can I do it?

Upvotes: 0

Views: 1076

Answers (1)

Umer Farooq
Umer Farooq

Reputation: 782

To make new window (stage) appear at the right side of current window (stage) use this

newWindow.setX(currentWindow.getX()+currentWindow.getWidth());
newWindow.setY(currentWindow.getY());
newWindow.show();

change + to - to make it appear on left side

Upvotes: 2

Related Questions