JavaFX - 如何创建瘦MenuBar? [英] JavaFX - How to create a thin MenuBar?
问题描述
我已经放置在 BorderPane
a MenuBar
的顶部,带有文件菜单和关闭 MenuItem
里面:
I've placed at the top of a BorderPane
a MenuBar
with a "File" Menu and a "Close" MenuItem
inside:
如何使它看起来更像我使用的大多数软件的 MenuBar
,类似于下图?
How can I make it look thinner like the MenuBar
s of most of the software I use, similar to the image below?
我认为它必须足够简单但作为初学者我无法'真的谷歌吧。我不确定如何命名问题(javafx菜单栏高度,尺寸,样式等没有太多有用的结果。)
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.)
推荐答案
将以下选择器添加到样式表会降低每个菜单元素的高度:
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;}
此外,您可以删除<$ c $的左右边距c> MenuBar 并减少间距:
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;
};
这篇关于JavaFX - 如何创建瘦MenuBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!