如何在使用FXML设计的JavaFX中创建内部弹出窗口 [英] How to create an inner popup in JavaFX styled with FXML

查看:522
本文介绍了如何在使用FXML设计的JavaFX中创建内部弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FXML文件,我用它来允许用户在请求时输入。现在我只是将它放在一个新的阶段并执行 Stage.show()。我希望它不会出现在一个新窗口中,表现得更像 ContextMenu

I have an FXML file that I'm using to allow user input when requested. Right now I just put it in a new stage and do Stage.show(). I would like to not have it appear in a new window and behave more like a ContextMenu.

看着 ContextMenu 类似乎我不能根据FXML文件设置内容。有没有办法用 ContextMenu Popup 或其他一些我不知道的类?

Looking at ContextMenu class it doesn't appear that I can set the content based off an FXML file. Is there a way to do this either with ContextMenu or Popup or some other class I am unaware of?

推荐答案

虽然该库非常好,但我想要一些简单的东西,不需要第三方下载。我想出了这个:

Although that library is quite nice, I wanted something simple that didn't require 3rd party downloads. I came up with this:

Popup popup = new Popup();
CustomController controller = new CustomController();
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlfile));
loader.setController(controller);
popup.getContent().add((Parent)loader.load());

问题是我没有意识到,$ c>可被视为节点 Popup#getContent #add

The problem was I didn't realize that a Parent could be considered a Node for the method Popup#getContent#add

这篇关于如何在使用FXML设计的JavaFX中创建内部弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆