SceneBuilder 2: Do controller classes need to nece

2019-03-31 12:37发布

问题:

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  

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 

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.

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.

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.

回答1:

This is a limitation of Scene Builder. Vote for DTL-5573 and DTL-5124.