如何在javafx中创建一个弹出窗口 [英] How to create a popup window in javafx
本文介绍了如何在javafx中创建一个弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 JavaFX 应用程序中创建一个弹出窗口.给我一些想法.
I want to create a popup window in a JavaFX application. Give me some ideas.
当我点击 Check 按钮时,它会打开弹出窗口.怎么做?
When I click on Check button it opens the popup window. How to do it?
推荐答案
您可以创建一个新的 Stage
,将您的控件添加到其中,或者如果您需要 POPUP 作为 Dialog
code> 框,那么您可以考虑使用 DialogsFX 或 ControlsFX(需要 JavaFX8)
You can either create a new Stage
, add your controls into it or if you require the POPUP as Dialog
box, then you may consider using DialogsFX or ControlsFX(Requires JavaFX8)
要创建新舞台,您可以使用以下代码段
For creating a new Stage, you can use the following snippet
@Override
public void start(final Stage primaryStage) {
Button btn = new Button();
btn.setText("Open Dialog");
btn.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
final Stage dialog = new Stage();
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.initOwner(primaryStage);
VBox dialogVbox = new VBox(20);
dialogVbox.getChildren().add(new Text("This is a Dialog"));
Scene dialogScene = new Scene(dialogVbox, 300, 200);
dialog.setScene(dialogScene);
dialog.show();
}
});
}
如果您不希望它是 modal
(阻止其他窗口),请使用:
If you don't want it to be modal
(block other windows), use:
dialog.initModality(Modality.NONE);
这篇关于如何在javafx中创建一个弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文