I have a modal class:
public class DialogModal
{
private String fxmlURL;
private int width;
private int height;
public DialogModal( String url, int w, int h )
{
fxmlURL = url;
width = w;
height = h;
}
public void showDialogModal(Button root) throws IOException
{
Stage modalDialog = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource( fxmlURL ));
Parent modalDialogRoot = loader.load();
Scene modalScene = new Scene( modalDialogRoot, width, height );
modalScene.getStylesheets().add(InventoryManager.class.getResource("InventoryManager.css").toExternalForm());
modalDialog.initOwner(root.getScene().getWindow());
modalDialog.setScene(modalScene);
modalDialog.setResizable(false);
modalDialog.showAndWait();
}
}
which is then opened thusly (from an FXML controller):
@FXML
private void handleModalButton(ActionEvent e) throws IOException
{
DialogModal modal = new DialogModal("Modal.fxml", 400, 450);
modal.showDialogModal((Button)e.getSource());
}
My question is, how do I get data from the modal (i.e., TextFields) back to my handleModalButton
method? This modal can be given different FXML files, so the data that it returns may be different.
Additionally, how do (or should) I send data to the modal (e.g., to populate TextFields)?
Thanks!