Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我';我在初级阶段_Java_Javafx - Fatal编程技术网

Java 当我';我在初级阶段

Java 当我';我在初级阶段,java,javafx,Java,Javafx,我试着用这个方法打印显示一个标签为“就是这样”的弹出窗口,我不想使用popup类 public void showStage(Stage Owner){ HBox hBox = new HBox(); hBox.getChildren().add(new Label("THAT'S IT")); Scene sc = new Scene(hBox); Stage popup = new Stage(); popup.setScene(sc);

我试着用这个方法打印显示一个标签为“就是这样”的弹出窗口,我不想使用popup类

    public void showStage(Stage Owner){

    HBox hBox = new HBox();
    hBox.getChildren().add(new Label("THAT'S IT"));
    Scene sc = new Scene(hBox);
    Stage popup = new Stage();
    popup.setScene(sc);
    popup.setWidth(400);
    popup.setHeight(100);
    popup.initOwner(owner);
    popup.initModality(Modality.WINDOW_MODAL);
    popup.show();
    }
然后我从start方法调用
showtage()
方法

     public void start(Stage primaryStage) {

    Label lb = new Label();

    btn.setText("Say 'Hello World'");
    btn.setOnAction(e->{
         lb.setText("hello everyone");showStage(primaryStage);
    });
但是代码的输出:


为什么不使用对话框? 您可以在主控制器类中使用它,而无需创建其他阶段,例如:

Dialog dialogQtPrescription = new Dialog();   
dialogQtPrescription.setTitle("yourTitle");
dialogQtPrescription.setHeaderText("yourHeadertext");
dialogQtPrescription.initModality(Modality.WINDOW_MODAL);
dialogQtPrescription.initOwner(mainStage);
dialogQtPrescription.initStyle(StageStyle.UTILITY);

GridPane gridDialogPrescription = new GridPane();
gridDialogPrescription.setHgap(10);
gridDialogPrescription.setVgap(10);
gridDialogPrescription.add(new Label(bundle.getString("quantityPrescription.title")), 0, 0);
TextField txtQtPrescr = new TextField();
ButtonType buttonTypeNo = new ButtonType("no");
ButtonType buttonTypeYes = new ButtonType("yes");
ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
dialogQtPrescription.getDialogPane().getButtonTypes().addAll(buttonTypeNo,buttonTypeYes, buttonTypeCancel);

txtQtPrescr.setPrefWidth(100);

gridDialogPrescription.add(txtQtPrescr, 1, 0);
dialogQtPrescription.getDialogPane().setContent(gridDialogPrescription);

Optional<ButtonType> result = dialogQtPrescription.showAndWait();
Dialog dialogqtpraction=newdialog();
dialogQT.setTitle(“您的标题”);
对话框qt.setHeaderText(“您的HeaderText”);
DialogQT.initModal(模态.WINDOW_模态);
dialogQT.initOwner(mainStage);
dialogQtPrescription.initStyle(StageStyle.UTILITY);
GridPane gridDialogPrescription=新建GridPane();
grid.setHgap(10);
grid.setVgap(10);
添加(新标签(bundle.getString(“quantityDescription.title”)),0,0;
TextField txtQtPrescr=新的TextField();
ButtonType buttonTypeNo=新的ButtonType(“否”);
ButtonType ButtonType是=新的ButtonType(“是”);
ButtonType buttonTypeCancel=新的ButtonType(“取消”,ButtonData.Cancel\u CLOSE);
dialogQtPrescription.getDialogPane().getButtonTypes().addAll(buttonTypeNo,buttonTypeYes,buttonTypeCancel);
txtQtPrescr.setPrefWidth(100);
gridDialogPrescription.add(txtQtPrescr,1,0);
dialogQtPrescription.getDialogPane().setContent(gridDialogPrescription);
可选结果=dialogQtPrescription.showAndWait();
这只是一个项目中的一堆代码,但我希望它能让您理解我的想法


这里有更好的解释:

您可以使用它在JavaFX的任何屏幕上弹出窗口

public void popup() {
        final Stage dialog = new Stage();
        dialog.setTitle("Confirmation");
        Button yes = new Button("Yes");
        Button no = new Button("No");

        Label displayLabel = new Label("What do you want to do ?");
        displayLabel.setFont(Font.font(null, FontWeight.BOLD, 14));

        dialog.initModality(Modality.NONE);
        dialog.initOwner((Stage) tableview.getScene().getWindow());

        HBox dialogHbox = new HBox(20);
        dialogHbox.setAlignment(Pos.CENTER);

        VBox dialogVbox1 = new VBox(20);
        dialogVbox1.setAlignment(Pos.CENTER_LEFT);

        VBox dialogVbox2 = new VBox(20);
        dialogVbox2.setAlignment(Pos.CENTER_RIGHT);

        dialogHbox.getChildren().add(displayLabel);
        dialogVbox1.getChildren().add(yes);
        dialogVbox2.getChildren().add(no);

        yes.addEventHandler(MouseEvent.MOUSE_CLICKED,
                new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent e) {
                        // inside here you can use the minimize or close the previous stage//
                        dialog.close();
                    }
                });
        no.addEventHandler(MouseEvent.MOUSE_CLICKED,
                new EventHandler<MouseEvent>() {
                    @Override
                    public void handle(MouseEvent e) {
                        dialog.close();
                    }
                });

        dialogHbox.getChildren().addAll(dialogVbox1, dialogVbox2);
        Scene dialogScene = new Scene(dialogHbox, 500, 40);
        dialogScene.getStylesheets().add("//style sheet of your choice");
        dialog.setScene(dialogScene);
        dialog.show();
    }
public void popup(){
最终阶段对话框=新阶段();
对话框。设置标题(“确认”);
按钮是=新按钮(“是”);
按钮编号=新按钮(“编号”);
Label displayLabel=新标签(“您想做什么?”);
displayLabel.setFont(Font.Font(null,fontwweight.BOLD,14));
dialog.initModality(Modality.NONE);
dialog.initOwner((Stage)tableview.getScene().getWindow());
HBox对话框HBox=新的HBox(20);
对话框HBox.setAlignment(位置中心);
VBox对话框VBOX1=新的VBox(20);
对话框VBOX1.设置对齐(位置居中左);
VBox对话框VBOX2=新的VBox(20);
对话框VBOX2.设置对齐(右中位置);
dialogHbox.getChildren().add(displayLabel);
dialogVbox1.getChildren().add(是);
dialogVbox2.getChildren().add(否);
是的。addEventHandler(MouseEvent.MOUSE_单击,
新的EventHandler(){
@凌驾
公共无效句柄(MouseEvent e){
//在这里,您可以使用最小化或关闭前一阶段//
dialog.close();
}
});
no.addEventHandler(MouseEvent.MOUSE_单击,
新的EventHandler(){
@凌驾
公共无效句柄(MouseEvent e){
dialog.close();
}
});
dialogHbox.getChildren().addAll(dialogVbox1,dialogVbox2);
场景dialogScene=新场景(dialogHbox,500,40);
dialogScene.getStylesheets().add(“//您选择的样式表”);
dialog.setScene(dialogScene);
dialog.show();
}
如果我修复了打字错误(
Stage Owner
->
Stage Owner
),我将无法重现此问题。由于答案中的信息不足以复制,或者只是一个简单的打字错误,所以投票选择接近主题。