As you can see below how the menu items are stretched, I want to do the same.
Asked
Active
Viewed 2,903 times
-1
-
1It's unclear what you're asking. The menu seems perfectly sized to fit two columns of justified text. Please clarify your specific problem or add additional details to highlight exactly what you need. An [mcve] will allow others to examine your approach. – trashgod Jul 10 '17 at 22:27
-
Possible duplicate -> [here](https://stackoverflow.com/questions/21209461/javafx-menu-item-show-shortcuts-on-right-hand-side). – SedJ601 Jul 11 '17 at 01:55
-
Is `setMinSize()` what your asking for? – Mordechai Jul 11 '17 at 04:04
-
This menu image is taken from Google I want to do same as this through FXML – ehsan abbas Jul 11 '17 at 09:56
3 Answers
1
The key to this is adding a KeyCombination
to menuItem.setAccelerator()
. The Menu
should automatically stretch when you add KeyCombinations
It will stretch based on your longest MenuItem
.
Programmatically:
MenuItem menuItem = new MenuItem("action");
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.T, KeyCombination.CONTROL_DOWN));
Menu menu = new Menu("File");
menu.getItems().add(menuItem);
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(menu);
FXML:
<MenuItem mnemonicParsing="true" text="action">
<accelerator>
<KeyCodeCombination alt="UP" code="T" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>

SedJ601
- 12,173
- 3
- 41
- 59
-1
<MenuBar>
<Menu text="Menu Item">
<items>
<MenuItem text="New" style="-fx-padding: 0 70 0 70"/>
<SeparatorMenuItem/>
<MenuItem text="Exit" style="-fx-padding: 0 70 0 70"/>
</items>
</Menu>
</MenuBar>

krishnaacharyaa
- 14,953
- 4
- 49
- 88
-2
This is kind of old, but for the future visitors: you can do this by using css file like this:
.menu-item {
-fx-padding: 5 5 80 5
}
You can play with the numbers to see what it changes.

a.2.c.4
- 51
- 1
- 5