JavaFX Adding a button to top-right of window
<p>I am designing a GUI in JavaFX and I've added to it a <code>MenuBar</code> with different <code>MenuItem</code>s. I also want it to be undecorated from the <code>Windows</code> default <code>Close</code> and <code>Minimize</code> buttons, so I've called the methods<code>initStyle(StageStyle.UNDECORATED)</code> on the <code>Stage</code> object. Now I'm trying to put a close button on the top right of the window so that my user can close the now resulted window, but I can't do so with the <code>BorderPane</code>s <code>setTop()</code> method, because it falls under the <code>MenuBar</code> item.<br>
Is there a way to float or add the button on top of the <code>MenuBar</code> ?<br>
Or at least have the <code>X</code> button in another menu bar that will be positioned before the current menu bar.</p>

<p>This is how it looks right now with the code I have:<br>
<a href="https://i.stack.imgur.com/RC15Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RC15Q.png" alt="enter image description here"></a><br>
This is the code I ahve so far in the <code>start()</code> method:</p>

<pre><code>public void start(Stage primaryStage) throws Exception {
    window = primaryStage;
    window.setTitle("Menu Example");


    MenuBar file = new MenuBar();
    file.setId("file");

    Menu fileMenu = new Menu("File");
    fileMenu.getItems().addAll(
            new MenuItem("New File..."),
            new MenuItem("Open file..."),
            new MenuItem("Save file"));
    fileMenu.setId("#fileMenu");



    Menu editMenu = new Menu("Edit");
    editMenu.getItems().addAll(
            new MenuItem("Undo"),
            new MenuItem("Redo"),
            new MenuItem("Cut"),
            new MenuItem("Copy"),
            new MenuItem("Paste")
    );

    Button closeButton = new Button("X");
    closeButton.setOnAction(event -&gt; {
        Platform.exit();
    });
//        closeButton.setAlignment(Pos.TOP_RIGHT);

    file.getMenus().addAll(
            fileMenu,
            editMenu

    );

    layout = new BorderPane();
    layout.setTop(file);
    layout.setRight(closeButton);

    Scene scene = new Scene(layout, 300, 300);
    scene.getStylesheets().add("Viper.css");
    window.setScene(scene);
//        window.setMaximized(true);
    window.initStyle(StageStyle.UNDECORATED);
    window.show();
}
</code></pre>