> is that correct so far?
Yes the sample code you have is fine to launch a new dialog when your Add button is pressed .
> I create the FXML and controller files for the participant dialog using NetBeans?
You can edit FXML text in NetBeans, but I think that is kind of tedious.
You might want to create the FXML using SceneBuilder.
You can use SceneBuilder in NetBeans.
You may want to get it working without FXML first.
For example, use the JavaFX scene graph API, then convert your program to use FXML once you are more comfortable with the JavaFX system.
The piecemeal approach cuts down on the amount of learning you need to do at one time.
> Should I create a separate project to make the participant dialog and then copy those files over.
Just use a single NetBeans project.
You will have separate FXML files for your main stage and your participant dialog, but they will both be placed in the same NetBeans project.
> is there a way to make the files within the parent project?
In NetBeans 7.3.1, do the following:
File | New Project | JavaFX | JavaFX FXML Application
This will create a sample project with a sample fxml file.
Modify the sample project files to get what you want, changing the sample fxml to your main stage fxml and adding a new participant fxml to the same directory.
I got it working, but now I have a follow up question.
How do I access variables in the associated controller. For example, one public boolean is simply isOK meaning the user selected OK to adding the participant (rather than Cancel to NOT add). How do I get access to isOK?
Here is my code:
Parent dlgRoot = FXMLLoader.load(getClass().getResource("SiRGCombatantDialog.fxml")); Scene scene = new Scene(dlgRoot); FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("SiRGCombatantDialog.fxml")); SiRGCombatantDialogController controller = fxmlLoader.getController(); final Stage participantDialog = new Stage(); participantDialog.setScene(scene); participantDialog.showAndWait(); boolean isOK = false; isOK = controller.isOK; if (isOK) Dialogs.showInformationDialog(participantDialog, "Message", "Header", "Title");
The line with fxmlLoader.getController() is returning null. Other than that, it is all working OK (although obviously since controller is null, it crashes on the line where I set isOK to controller.isOK). So clearly I am missing something as far as getting at the controller.
How do I get access to the controller class?
> I got it working
> How do I access variables in the associated controller.
This is the most common question related to FXML.
The short answer is either:
1. Create a controller and set it on the FXMLLoader instance *before* calling load OR
2. Load an FXML using the FXMLLoader instance, then get the controller from the loader *after* loading the FXML.
And in both case add appropriate access methods to your controller to get or set the state of the controller.
More complete answers are in these links: