我正在使用Jfoenix,JFXDialog
没有出现。
我做错了什么?这是代码:
JFXDialogLayout content= new JFXDialogLayout();
content.setHeading(new Text("Error, No selection"));
content.setBody(new Text("No student selected"));
StackPane stackpane = new StackPane();
JFXDialog dialog =new JFXDialog(stackpane, content, JFXDialog.DialogTransition.CENTER);
JFXButton button=new JFXButton("Okay");
button.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
dialog.close();
}
});
content.setActions(button);
dialog.show();
答案 0 :(得分:3)
您正在做的是,您将JFXDialog添加到StackPane并显示对话框。由
$ret = @()
foreach ($item in $items){
$subret = @()
$subRet = $item.Name , $item.Value
$ret += $subret
}
实际上,它的作用是在堆栈窗口内显示对话框创建的对话框。问题是堆栈窗从未显示,因此对话框也永远不会显示。这就像在计算机关闭时尝试打开文档一样。
首先,这部分是完全正确的
JFXDialog dialog =new JFXDialog(stackpane, content, JFXDialog.DialogTransition.CENTER);
....
....
....
dialog.show();
此后如果stackpane是您的根窗格,只需从中创建场景并分别显示primaryStage和对话框(实际上您不必先显示primaryStage,然后再显示对话框,但此顺序更有意义)。
JFXDialogLayout content= new JFXDialogLayout();
content.setHeading(new Text("Error, No selection"));
content.setBody(new Text("No student selected"));
StackPane stackpane = new StackPane();
JFXDialog dialog =new JFXDialog(stackpane, content, JFXDialog.DialogTransition.CENTER);
JFXButton button=new JFXButton("Okay");
button.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
dialog.close();
}
});
content.setActions(button);
如果您已经有另一个根窗格,则在显示primaryStage和对话框之前将堆栈窗格添加到其中。
Scene scene = new Scene(stackpane, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
dialog.show();
primaryStage来自Application类的overrided start方法。以下是根窗格为 stackpane 的那个。
AnchorPane root = new AnchorPane();
....
.... //Some other Nodes here
JFXDialogLayout content= new JFXDialogLayout();
content.setHeading(new Text("Error, No selection"));
content.setBody(new Text("No student selected"));
StackPane stackPane = new StackPane();
JFXDialog dialog =new JFXDialog(stackPane, content, JFXDialog.DialogTransition.CENTER);
JFXButton button=new JFXButton("Okay");
button.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
dialog.close();
}
});
content.setActions(button);
Scene scene = new Scene(root, 300, 250);
root.getChildren().add(stackPane);
primaryStage.setScene(scene);
primaryStage.show();
dialog.show();