5

I am using Scene Builder to create my GUI and my menu bar isn't resizing to the parent. How do i get it to do this?

When I try Modify -> Fit to Parent, the menu bar takes up the whole root pane, and obviously this isn't what i want. Here is an image of what i am talking about:

enter image description here

As you can see, the menu bar doesn't fully extend to the end of the window.

j will
  • 3,747
  • 11
  • 41
  • 64

3 Answers3

15

You need to bind the preferred width property of your menu bar to the width of your stage or some other container node. It works when you dynamically resize too.

menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
Unheilig
  • 16,196
  • 193
  • 68
  • 98
12

I had to set the anchor pane constraints in the menu bar. I had to make the left and right margins zero:

enter image description here

j will
  • 3,747
  • 11
  • 41
  • 64
  • 1
    What most of us are missing here, is that the menuBar has to be a direct child of the AnchorPane. Thanks a lot :) – thanassis Apr 18 '16 at 09:41
  • 1
    This solution works without coding, using only scene builder, which is what j will and I were both looking for. Not obvious in scene builder I have to say! – Cloudranger Jun 06 '17 at 17:19
3

MenuBarHBoxWrappingHere is another way to do it. Wrap MenuBar in a HBOX. Set MenuBar's HGrow to ALWAYS. Set HBOX Node Alignment to TOPLEFT.

lochi
  • 860
  • 2
  • 12
  • 26