I am working on a JavaFX, Jfoenix desktop application where I have multiple FXML views. The application is supposed to recognize in real-time when a specific embedded device was connected or disconnected. Unfortunately, there is no interrupt function for this, so I am forced to constantly pool in a separate thread running from the main view. The thing is, I have to detect this change (when a device is connected and disconnected) from different views, not just on the main one. And since every view has its own controller and many GUI elements are injected using SceneBuilder
, I cannot touch any of those, so I can't make a listener on a TextBox
for example.
Is there any way that I could constantly listen in other views for something like a boolean flag change that was made in the pooling thread from the main view?
Something like this, listening for changes of the boolean variable: isHiConnected
. This code is running in a JavaFX Service that implements a Task:
if (textName != "Disconnected") {
if(!recentChange1) {
isHiConnected = true;
recentChange1 = true;
recentChange2 = false;
}
} else {
if(!recentChange2) {
isHiConnected = false;
recentChange2 = true;
recentChange1 = false;
}
}