JavaFX - How to create a thin MenuBar?

前端 未结 1 1449
我寻月下人不归
我寻月下人不归 2021-01-12 07:16

I\'ve placed at the top of a BorderPane a MenuBar with a \"File\" Menu and a \"Close\" MenuItem inside:

How can I mak

相关标签:
1条回答
  • 2021-01-12 08:20

    Adding the following selectors to you stylesheet reduces the height of each menu element:

    .menu-item { -fx-padding: 1 5 1 5; }
    .menu { -fx-padding: 1 5 1 5; }
    

    To remove the padding of all context menus, you can additionally add:

    .menu .context-menu { -fx-padding: 1 1 1 1; }
    

    And you can also decrease the font size:

    .menu-item >.label {-fx-font-size:9;}
    .menu >.label {-fx-font-size:9;}
    

    Furthermore you can remove the left right padding of the MenuBar and decrease the spacing:

    .menu-bar {
      -fx-padding: 0 1 0 1;
      -fx-spacing: 1;
    };
    

    0 讨论(0)
提交回复
热议问题