无法显示第二个 JavaFX 阶段?
Can't get second JavaFX stage to show?
我正在编写一个 RDP 客户端,我想在保留旧阶段的同时展示一个新阶段 运行ning。不幸的是,第二阶段根本没有出现。
这是我的舞台:
public final class Remote extends Stage {
private static final URL FXML = Remote.class
.getResource("/conspire/remote.fxml");
private static final Image ICON = new Image(Remote.class.getResource(
"icon.png").toExternalForm());
public static Remote create(String title) throws IOException {
return new Remote(title);
}
private Remote(String title) throws IOException {
Parent parent = FXMLLoader.load(FXML);
Scene scene = new Scene(parent);
setScene(scene);
getIcons().add(ICON);
setTitle(title);
setResizable(true);
centerOnScreen();
show();
}
}
这就是我 运行 的方式:
Remote.create(host + " (" + partner.getValue() + ") - Conspire");
create 方法甚至不会调用。如果我在其中添加系统输出,它不会打印。
为了创建一个新阶段,您必须 运行 从 JavaFX 线程中创建它。您可以使用 JavaFX 的 Platform 工具轻松完成此操作。你的情况:
Platform.runLater(() -> {
Remote.create(host + " (" + partner.getValue() + ") - Conspire");
});
我正在编写一个 RDP 客户端,我想在保留旧阶段的同时展示一个新阶段 运行ning。不幸的是,第二阶段根本没有出现。
这是我的舞台:
public final class Remote extends Stage {
private static final URL FXML = Remote.class
.getResource("/conspire/remote.fxml");
private static final Image ICON = new Image(Remote.class.getResource(
"icon.png").toExternalForm());
public static Remote create(String title) throws IOException {
return new Remote(title);
}
private Remote(String title) throws IOException {
Parent parent = FXMLLoader.load(FXML);
Scene scene = new Scene(parent);
setScene(scene);
getIcons().add(ICON);
setTitle(title);
setResizable(true);
centerOnScreen();
show();
}
}
这就是我 运行 的方式:
Remote.create(host + " (" + partner.getValue() + ") - Conspire");
create 方法甚至不会调用。如果我在其中添加系统输出,它不会打印。
为了创建一个新阶段,您必须 运行 从 JavaFX 线程中创建它。您可以使用 JavaFX 的 Platform 工具轻松完成此操作。你的情况:
Platform.runLater(() -> {
Remote.create(host + " (" + partner.getValue() + ") - Conspire");
});