首页 / JAVA / JavaFX下拉按钮
JavaFX下拉按钮
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JavaFX下拉按钮,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1358字,纯文字阅读大概需要2分钟。
内容图文
![JavaFX下拉按钮](/upload/InfoBanner/zyjiaocheng/746/9d440ea3886e4825a0be834167fa5c03.jpg)
如何在JavaFX中创建“下拉按钮”?
到目前为止,我正在使用ChoiceBox,现在我必须为ChoiceBox分配一个图像,
ChoiceBox.setGraphic() // is not available as like
Buttons
所以我打算把它改成一个下拉按钮.这样我就可以设置一个图标了.
我使用SceneBuilder设计UI.
没有帮助搜索如何使用JavaFX创建下拉按钮.
解决方法:
如果您不必像在ChoiceBox中那样存储选择,则可以使用例如MenuButton控件.
MenuButton is a button which, when clicked or pressed, will show a
ContextMenu.
一个MenuButton有你提到的graphicProperty,因为它的基类是Labeled.
简单的例子
final Image image = new Image(getClass().getResource("cross_red.png").toExternalForm(), 20, 20, true, true);
MenuButton menuButton = new MenuButton("Don't touch this");
menuButton.setGraphic(new ImageView(image));
menuButton.getItems().addAll(new MenuItem("Really"), new MenuItem("Do not"));
这将生成一个按钮,如:
注意:如果您需要按钮也像真正的按钮一样,您可以从MenuButton切换到SplitMenuButton.唯一的区别是控制字段被分为按钮部分和下拉部分(因此您也可以分配操作为标题):
The SplitMenuButton, like the MenuButton is closely associated with
the concept of selecting a MenuItem from a menu. Unlike MenuButton,
the SplitMenuButton is broken into two pieces, the “action” area and
the “menu open” area.If the user clicks in the action area, the SplitMenuButton will act
similarly to a Button, firing whatever is associated with the
ButtonBase.onAction property.
内容总结
以上是互联网集市为您收集整理的JavaFX下拉按钮全部内容,希望文章能够帮你解决JavaFX下拉按钮所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。