您的位置:首页 > 编程语言 > Java开发

javaFX 可控制自动关闭时间的弹出提示窗口

2016-10-24 18:48 399 查看
public static void showTimedDialog(long time, String message) {
Stage popup = new Stage();
popup.setAlwaysOnTop(true);
popup.initModality(Modality.APPLICATION_MODAL);
Button closeBtn = new Button("知道了");
closeBtn.setOnAction(e -> {
popup.close();
});
VBox root = new VBox();
root.setPadding(new Insets(20));
root.setAlignment(Pos.BASELINE_CENTER);
root.setSpacing(20);
root.getChildren().addAll(new Label(message), closeBtn);
Scene scene = new Scene(root);
popup.setScene(scene);
popup.setTitle("提示信息");
popup.show();

Thread thread = new Thread(() -> {
try {
Thread.sleep(time);
if (popup.isShowing()) {
Platform.runLater(() -> popup.close());
}
} catch (Exception exp) {
exp.printStackTrace();
}
});
thread.setDaemon(true);
thread.start();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javafx