1

I want to have a menu for my program. And I like the standard Menu look and all, but I want to place a "logout-button" on the far right side of the menu-bar.. is it possible to place it there WITHOUT having to fill up the whole menu-bar with entries?

Sincerely

Andrew
  • 4,574
  • 26
  • 31
haakonlu
  • 949
  • 3
  • 13
  • 25

1 Answers1

2

Yes you can. Use the HBox#setHgrow();. This javadoc page also has an example how to use it in "Optional Layout Constraints" section. Following is taken from javadoc.

For example, if an hbox needs the TextField to be allocated all extra space:

     HBox hbox = new HBox();
     TextField field = new TextField();
     HBox.setHgrow(field, Priority.ALWAYS);
     hbox.getChildren().addAll(new Label("Search:"), field, new Button("Go"));

Briefly speaking, set Priority.ALWAYS for the button (or any control) just before the "logout-button" in a HBox. More advanced example is here: Using Built-In Layout Panes : Example 1-4

Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • Thanks a lot! :D Here's another Question I have: http://stackoverflow.com/questions/10315774/javafx-2-0-menu-menubar-menuitem – haakonlu Apr 25 '12 at 12:38
  • This is a nice solution for Nodes in HBoxes. But how would one apply it to Menus in a MenuBar? Did I miss something? – andreas Mar 04 '13 at 12:21
  • 1
    @andreas. With a default menu style, putting 2 different menuBars into HBox and giving a "ALWAYS" priority to the first menuBar visually accomplishes the desired effect for menus in a menubar(s). – Uluk Biy Mar 04 '13 at 18:09