[英]Positioning MenuButton's ContextMenu using css in JavaFX2
I was searching about how to set co-ordinate of MenuButton
's Context Menu in css and didn't find a way to achieve. 我正在搜索有关如何在CSS中设置
MenuButton
的上下文菜单的坐标的方法,但没有找到实现方法。 I want to lower the Conext Menu from actual position like attached example images and if possible then up arrow too. 我想从实际位置降低Conext菜单,如附加的示例图像,如果可能的话,也可以向上箭头。 Take a look at my code.
看一下我的代码。
<MenuButton layoutX="1046.0" layoutY="38.0" mnemonicParsing="false" prefHeight="30.0" prefWidth="30.0" styleClass="notification-button">
<graphic>
<Pane>
<children>
<Circle fill="#db5344" layoutX="20.0" radius="10.0" stroke="BLACK" strokeType="OUTSIDE" strokeWidth="2.0" />
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="12.3" layoutY="-8.5" prefHeight="10.0" prefWidth="15.0" text="0" textAlignment="CENTER" />
</children>
</Pane>
</graphic>
<items>
<MenuItem mnemonicParsing="false" text="Sample" />
</items>
</MenuButton>
.menu-button > .arrow-button {
-fx-padding: 0;
}
.menu-button > .arrow-button > .arrow {
-fx-padding: 0;
}
.menu-item {
-fx-padding: 10;
}
.menu-item .label {
-fx-text-fill: white;
}
.menu-item:focused {
-fx-background-color: darkgray;
}
.menu-item:focused .label {
-fx-text-fill: blue;
}
.menu-item .label {
-fx-text-fill: yellow;
}
.menu-item:focused .label {
-fx-text-fill: white;
}
.context-menu {
-fx-skin: "com.sun.javafx.scene.control.skin.ContextMenuSkin";
-fx-text-fill: white;
-fx-background-color: #006699;
-fx-background-insets: 0, 1, 2;
-fx-background-radius: 0 6 6 6, 0 5 5 5, 0 4 4 4;
-fx-padding: 10px;
}
.context-menu .separator {
-fx-padding: 10;
}
.context-menu .container {
-fx-padding: 10;
}
.context-menu .scroll-arrow {
-fx-padding: 10;
-fx-background-color: #006699;
}
.context-menu .scroll-arrow:hover {
-fx-background: -fx-accent;
-fx-background-color: #006699;
-fx-text-fill: -fx-selection-bar-text;
}
.context-menu:show-mnemonics .mnemonic-underline {
-fx-stroke: -fx-text-fill;
}
The below attached images will help you understand my question. 以下所附图片将帮助您理解我的问题。 First image is output of my current code, the second and third image is what I want.
第一张图片是我当前代码的输出,第二张和第三张图片是我想要的。 both second and third images are for custom styling for drop down in webpages.
第二张和第三张图片均用于自定义样式,以在网页中下拉。 Can I achieve the same in JavaFX2?
我可以在JavaFX2中实现相同的功能吗?
As you can see my fxml code, I have used MenuButton
and MenuItem
inside it. 如您所见,我在fxml代码中使用了
MenuButton
和MenuItem
。 If you think this won't help. 如果您认为这没有帮助。 Please tell me other ways for getting it.
请告诉我其他获取方式。
Well, I am sure there are lots of developers who knows how to do this. 好吧,我敢肯定有很多开发人员知道如何做到这一点。 May be they didn't have time for this or unaware of my question.
可能是他们没有时间解决这个问题或没有意识到我的问题。
By the way, I wasted almost 2 days behind this. 顺便说一下,我浪费了将近2天的时间。 But happy that I was able to do the solution.
但很高兴我能够解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.