简体   繁体   English

JavaFX-如何创建一个精简的MenuBar?

[英]JavaFX - How to create a thin MenuBar?

I've placed at the top of a BorderPane a MenuBar with a "File" Menu and a "Close" MenuItem inside: 我在BorderPane的顶部放置了一个MenuBar其中带有“文件”菜单和“关闭” MenuItem

厚菜单栏

How can I make it look thinner like the MenuBar s of most of the software I use, similar to the image below? 如何使它看起来像我使用的大多数软件的MenuBar一样薄,类似于下图?

厚菜单栏

I think it must be simple enough but as a beginner I couldn't really google it. 我认为它必须足够简单,但是作为一个初学者,我真的不能用谷歌搜索它。 I'm not sure how to name the problem (not many useful results for "javafx menubar height", size, styling, etc.) 我不确定如何命名问题(“ javafx菜单栏高度”,大小,样式等没有很多有用的结果)

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: 此外,您可以删除MenuBar左右填充并减小间距:

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM