Forum Stats

  • 3,874,067 Users
  • 2,266,672 Discussions


How to resize menuitems?

awacs5 Member Posts: 17
edited Apr 11, 2017 7:19PM in JavaFX 2.0 and Later

I thought menuitems would have a size method or some sort to control the size, but I cannot find any.

How do people resize menuitems in a menubutton?

For example if I create a menubutton in scene builder, the menu items have a very small width. If I widen the menubutton the menu items stay the same size. The only way I've found so far is to a pane to the item in scene builder, but in java code I can't see how this can be done.

Has anyone had the need to resize menu items??


  • bouye-JavaNet
    bouye-JavaNet Member Posts: 394 Silver Badge
    edited Apr 11, 2017 7:19PM

    But the MenuItem and Menu classes are not inheriting from Node at all if you look at the class hierarchy in the javadoc so thy do not have any method for sizing. The problem here is the MenuItem object and what's rendered in the menu (or event the menu itself) on the screen is not the same. FX may decide to use its own node-based scene-included rendering for menus and menuitems or completely switch to the native system's ways of doing menus (ie: the Mac system bar for example ; a side, popup or hidden menu on mobile). This allows to make menus and menuitems more portable to multiple platform but also they do not work or act like other regular nodes (because they aren't, they're just placeholders).

    For your MenuButton issue, you may want to investigate CSS to see if it's feasible to enlarge the popup / context menu in which the menuitems are rendered. The popup itself and it's content will have CSS selectors so you can try to play with it.

    Or you may want to provide your own MenuButton skin that always resize the popup to the width of the button before displaying it.

This discussion has been closed.