I am new to JavaFX and I am trying to do following:
I have main class with UI, important part being
public class Main extends Application {
...
scene = new Scene(new Group());
final Label label = new Label("Device name");
label.setFont(new Font("Arial", 20));
label.setId("label");
DeviceConnector connector = new DeviceConnector(scene);
}
In class in other file I have some chained threads. Last of them if each successful (they connect to bluetooth) reads device name. This is what I want to display on the label from above.
Unfortunately I have not found any other (rather ellegant) solution than this:
public class DeviceConnector {
Scene mScene;
public DeviceConnector(Scene scene) {
mScene = scene;
}
private void ReadDeviceName {
this.deviceName = device.GetName();
Platform.runLater(new Runnable() {
@Override
public void run() {
Label label = (Label) mScene.lookup("#label");
label.setText(deviceName);
}
});
}
}
Is there any proper way to access components in JavaFX GUI (something like Mediator pattern)?
Thank you.