Icedude_907 Icedude_907 - 28 days ago 7
Java Question

JavaFX: MenuBar showing "..."

So: i have here a piece of code that I am using to add a menu to my application.

Stage window;

private void buildWindow() {
window = new Stage();
window.setTitle("FACE");

//MENU
MenuBar mBLaunch = new MenuBar();
Menu fileLaunch = new Menu("File");
MenuItem saveLaunch = new Menu("Save");
MenuItem exitLaunch = new MenuItem("Exit");
fileLaunch.getItems().addAll(saveLaunch, new SeparatorMenuItem(), exitLaunch);
mBLaunch.getMenus().add(fileLaunch);


//HouseKeeping
BorderPane bPLaunch = new BorderPane();
bPLaunch.getChildren().addAll(mBLaunch);
Scene launch = new Scene(bPLaunch);
window.setScene(launch);
window.setMinHeight(500);
window.setMinWidth(500);
window.show();

}


However: when I run this code it produces:This

So, my question being, how can I make it display something else than ...?
Thanks for the help in advance.

VGR VGR
Answer

BorderPane places each child at a specific location: center, top, bottom, left, right. If you just add nodes to its list of children, it doesn’t know where to place them.

Replace this:

bPLaunch.getChildren().addAll(mBLaunch);

with this:

bPLaunch.setTop(mBLaunch);
Comments