I'm trying to figure out if blocking the GUI is possible. Basically, my application (using NetBeans Platform and JavaFX ) has a server connection.
No matter what screen the user sees, if the application loses connection with the server, I would like to block everything (users cannot open any new windows or click anywhere) until the application is connected again (this does not mean if it is needed 5 minutes or 5 hours). However, a warning message should appear at the top of everything (always on top).
The java class that listens for the connection to the server has no reference to JavaFX containers. This is what I actually have:
public class StatusConnectionObserver implements ConnectionObserver { private final Led led; private final Label label; public StatusConnectionObserver(Led led, Label label) { this.led = led; this.label = label; } @Override public void setConnected(boolean connected) { if (connected) { Platform.runLater(() -> { led.setLedColor(Color.rgb(59, 249, 53)); label.setText("Connected"); }); } else { Platform.runLater(() -> { led.setLedColor(Color.RED); label.setText("Disconnected"); }); } } }
and
public class ConnectionComponent { private Led led; private Label label; private HBox container; private VBox ledContainer; public ConnectionComponent() { initGraphics(); } public Parent getView() { return this.container; } public void initGraphics() {
What is called here:
@ServiceProvider(service = StatusLineElementProvider.class) public class ConnectionIndicator implements StatusLineElementProvider { @Override public Component getStatusLineElement() { JFXPanel fxPanel = new JFXPanel(); Platform.setImplicitExit(false); new JavaFXUIThread().runOnUiToolkitThread(() -> { Scene scene = new Scene(new ConnectionComponent().getView()); scene.getStylesheets().add(FXTheme.getDefault().getStylesheet()); fxPanel.setScene(scene); }); return fxPanel; } }
The idea is to show something on top (even a simple text message) and, in the meantime, make the application in the background more opaque.
source share