I have one window with a Label and a Button, and another window with a TextField and a Button. From the main window I want to open the other window using the button, enter something in the text field on the new window, and after clicking the button on the new window I want it to close and the main window label to update with the text that was entered. Also I want the new window to be modal.
public class MainController {
@FXML
public void showNewWindow() {
try {
Stage newWindowStage = new Stage();
newWindowStage.setTitle("New Window");
newWindowStage.initModality(Modality.APPLICATION_MODAL);
VBox root = FXMLLoader.load(getClass().getResource("newWindow.fxml"));
Scene scene = new Scene(root);
newWindowStage.setScene(scene);
newWindowStage.showAndWait();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class NewWindowController {
@FXML
private TextField textField;
@FXML
public void updateMainWindowLabel() {
// update label in main window
// close new window
}
}
I know it's not set up right at all but hopefully it explains what I'm trying to do.