问题描述
我喜欢JavaFX和SceneBuilder,但是当我们不在同一个文件夹中时,我无法弄清楚如何让SceneBuilder将我的FXML视图链接到他们的Java控制器。我只想拥有这个文件夹结构:
I'm loving JavaFX and SceneBuilder, but I just can't figure out how to make SceneBuilder link my FXML views with their Java controllers when they are not in the same folder. I'd just like to have this folder structure:
package
|-- model
|-- view
| |--someElementView.fxml
| \--anotherElementView.fxml
\-- control
|--someElementController.java
\--anotherElementController.java
相反,我只能让SceneBuilder识别我的控制器,如果我有这个文件夹结构,我想避免:
Instead I can only make SceneBuilder recognise my controllers if I have this folder structure which I'd like to avoid:
package
|-- model
\-- view
|--someElementView.fxml
|--anotherElementView.fxml
|--someElementController.java
\--anotherElementController.java
当FXML和java文件都在同一个文件夹中时,会发生什么情况,SceneBuilder会检测到它们并显示带有java控制器的下拉列表(即package.view.someElementController和package.view.anotherElementController)选择,一切都很好。
What happens is that when the FXML and java files are all in the same folder, SceneBuilder detects them and shows a dropdown list with the java controllers (i.e. "package.view.someElementController" and "package.view.anotherElementController") for me to choose from and everything works nicely.
如果我有一个项目文件夹结构与控制器在一个单独的文件夹中,SceneBuilder将不会为我提供任何分配控制器类的选项。如果我只是在控制器文本字段中键入它(即package.control.someElementController或package.control.someElementController),它仍然不会获取java控制器中定义的@FXML变量。
If I have a project with the folder structure with the controllers in a separate folder, SceneBuilder won't offer me any option to assign a controller class. If I just type it in the controller text field (i.e. "package.control.someElementController" or "package.control.someElementController"), it still won't pick up the @FXML variables defined in the java controller.
这是Scene Builder中的错误还是我接近错误的方式?我总是把控制器和视图放在不同的文件夹中,因为它是一个大项目,我想保持整洁。
Is this a bug in Scene Builder or am I approaching things the wrong way? I have always have the controllers and the views in different folders, and since it's a big project, I'd like to keep things tidy.
推荐答案
这是Scene Builder的限制。投票选择和。
This is a limitation of Scene Builder. Vote for DTL-5573 and DTL-5124.
这篇关于SceneBuilder 2:控制器类是否必须与视图FXML文件位于同一文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!