本文介绍了如何在javafx中创建弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在javafx application中创建一个弹出窗口。给我一些想法。
I want to create a popup windows in javafx application.give me some idea.
当我点击复选按钮打开弹出窗口时。
怎么办?
when i click on check button open popup windows.how to do?
推荐答案
你可以创建一个新的 Stage
,将控件添加到其中,或者如果您需要POPUP作为 Dialog
框,那么您可以考虑使用或(需要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();
}
});
}
如果你不希望它是模态
(阻止其他窗口),使用:
If you don't want it to be modal
(block other windows), use:
dialog.initModality(Modality.NONE);
这篇关于如何在javafx中创建弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!