[英]JavaFx menu item accelerator Javafx css
I have tried to iconified JavaFX menu item label. 我试图将JavaFX菜单项标签图标化。 I got the icon duplicated for both menu item label and accelerator label.
我为菜单项标签和加速器标签都复制了图标。 Here is an image that illustrates my issue.
这是一张说明我的问题的图片。
Here is the Javafx css code: 这是Javafx css代码:
.menu-item > .label {
}
#miRestore .label{
-fx-graphic: url("/img/Upload_16x16.png");
}
#miBackup .label {
-fx-graphic: url("/img/Flash%20Disk_16x16.png");
}
#miClose .label {
-fx-graphic: url("/img/Delete_16x16.png");
}
#miSettings .label {
-fx-graphic: url("/img/Settings_16x16.png");
}
#miRegistre . label{
-fx-graphic: url("/img/Help_16x16.png");
}
I have found a reliable solution to this: in Scene Builder / FXML (whatever you prefer), attach a Style Class (not id) to every menu-Item you want to have an icon. 我找到了一个可靠的解决方案:在Scene Builder / FXML(无论你喜欢什么)中,将样式类(不是id)附加到你想拥有一个图标的每个菜单项。 Now add a stylesheet to the menubar in which you put the following CSS for every item with an icon:
现在在菜单栏中添加一个样式表,在其中为每个带有图标的项目放置以下CSS:
.yourClassName > .label{
-fx-graphic: url("yourImageUrl");
}
At the end of the CSS file, add the following to remove all the second images: 在CSS文件的末尾,添加以下内容以删除所有第二个图像:
.context-menu .accelerator-text{
-fx-graphic: none;
}
What this does is set the -fx-graphic of every -accelerator-text to 'none'. 这样做是将每个-accelerator-text的-fx-graphic设置为'none'。 So it basically removes the image again.
所以它基本上会再次移除图像。
Now you will only have icons in front of your menu-Item Text, not the accelerator text. 现在,菜单项目文本前面只有图标,而不是加速器文本。 To give you a concrete idea on how this is done I have made a small example for you:
为了让您具体了解如何完成此操作,我为您做了一个小例子:
which is the result of following CSS stylesheet added to my menubar, and corresponding CSS Style Classes added to my menu-Items: 这是将以下CSS样式表添加到我的菜单栏中的结果,以及添加到我的菜单中的相应CSS样式类 - 项目:
.newIcon > .label{
-fx-graphic: url("px16/file.png");
}
.openIcon > .label{
-fx-graphic: url("px16/folderEmpty.png");
}
.closeIcon > .label{
-fx-graphic: url("px16/minus.png");
}
.saveIcon > .label{
-fx-graphic: url("px16/save.png");
}
.saveAsIcon > .label{
-fx-graphic: url("px16/folder.png");
}
.quitIcon > .label{
-fx-graphic: url("px16/error.png");
}
.context-menu .accelerator-text{
-fx-graphic: none;
}
This was my first answer here on StackOverflow, I hope this will be helpful to someone. 这是我在StackOverflow上的第一个答案,我希望这对某人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.