db9*_*b92 5 java javafx netbeans-platform
我想弄清楚是否可以阻止GUI.基本上,我的应用程序(使用NetBeans平台和JavaFX)与服务器有连接.
无论用户看到哪个屏幕,如果应用程序丢失了与服务器的连接,我想阻止所有内容(用户无法打开任何新窗口或点击任何地方),直到应用程序再次连接为止(无论是否重要)需要5分钟或5个小时).尽管如此,最重要的是应该出现一条警告信息(始终在顶部).
正在侦听服务器连接的java类没有对JavaFX容器的任何引用.这就是我实际拥有的:
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");
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
和:
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() {
//Here I set up the elements (label and Led) inside the container
}
Run Code Online (Sandbox Code Playgroud)
这里叫做:
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
我们的想法是在顶部显示一些内容(即使是简单的文本消息),同时使应用程序在后台更加不透明.
归档时间: |
|
查看次数: |
560 次 |
最近记录: |