I'm using SceneBuilder in conjunction with Netbeans' JavaFX library for this project. I use Scenebuilder to create the fxml and netbeans for the controller classes. The goal is to build a fairly complex app that is to be deployed.
I can launch a JavaFX application and hook up the controller class just fine. However, when I try to open a new window I can't seem to bind a controller class to the new window. To keep things simple I would like to have a separate controller class for the new window due to a complex back-end.
TL;DR -- Trying to open a new window on JavaFX application with a controller class. Controller class isn't binding.
Code samples below
Model class -- wrapper for launching the application
public class Model extends Application{
public static void main(String[] args){
Application.launch(Model.class, args);
}
@Override
public void start(Stage stage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
stage.setScene(new Scene(root));
stage.show();
}
}
Sample.fxml -- fxml file for the main application
Sample.java -- extends Initializable, is the controller class for Sample.fxml. Below is code snippet where I try to open the new window titled "ServerConfigChooser
try{
Parent root = FXMLLoader.load(getClass().getResource("ServerConfigChooser.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("ServerConfigChooser.fxml"));
ServerConfigChooser controller = new ServerConfigChooser();
loader.setController(controller);
loader.setRoot(root);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.show();
} catch (IOException ex)
ServerConfigChooser.java -- implements Initializable
This is where I have the problems. I cannot simply declare variables with the same fxid as the variables in the .fxml file. The initialize() method does not fire when the class is called.
The reason for the constructor in the ServerConfigChooser class is that I could not fire the initialize() method automatically. I fire that manually within the constructor.
Any solutions are welcome!