I have one main Scene, where I keep all mu GUI. It has a menu, which opens new scenes, where I have some settings:
public class StartController implements Initializable {
// Some other fields
@FXML
private TextArea eventLog;
// This method opens "new project" window
@FXML
private void openProjectWindow(Event event) throws IOException {
eventLog.appendText(EventLogUtils.getDate() + STATUS.INFO
+ " New project window opened\n");
GridPane newProjectWindow = (GridPane) FXMLLoader.load(getClass()
.getResource("../view/project.fxml"));
Scene scene = new Scene(newProjectWindow, 800, 600);
scene.getStylesheets().add(
getClass().getResource("../view/main.css").toExternalForm());
Stage projectStage = new Stage();
projectStage.setScene(scene);
projectStage.setTitle("New Project");
projectStage.show();
}
}
This eventLog TextArea is a place where I put all the logs, like application started, settings changed, project saved etc. I'm opening new scene with openProjectWindow void and I'm adding this information to my logger. My new window is a separate class:
public class ProjectWindowController implements Initializable {
// fields and methodes to fill and save forms
}
Once It's done I need to access StartController.eventLog somehow, but nothing I tried is working:
- Changing eventLog to public
- Extending StartController by ProjectWindowController and trying super.eventLog.appendText()
- Changing eventLog to public static (throws exception during runtime)
Is there any way to access this field from different Stage (Class) ? I'd normally use Singleton design pattern, but I think it's impossible in this case. I was looking for similar questions, but I didn't find any case matching my problem. Thanks for any help!