事件筛选器不起作用

时间:2013-09-06 16:26:46

标签: java javafx-2 javafx javafx-8

我有一个无法正常工作的事件监听器,我找不到原因:

public void initCloseConfigurationPanelDialog(final Stage primaryStage)
    {

        final Stage dialog = new Stage();
        // If you want to freeze the background during dialog appearence set 
        dialog.initModality(Modality.APPLICATION_MODAL);
        dialog.initOwner(primaryStage);

        // Button "Yes"
        Button btnYes = new Button("Yes");

        btnYes.setOnAction(new EventHandler<ActionEvent>()
        {
            @Override
            public void handle(ActionEvent event)
            {

                primaryStage.close();
            }
        });

        btnYes.setDefaultButton(true);

        // Button "No"
        Button btnNo = new Button("No");

        btnNo.setOnAction(new EventHandler<ActionEvent>()
        {
            @Override
            public void handle(ActionEvent event)
            {
                primaryStage.show();
                dialog.close();
            }
        });

        btnNo.setCancelButton(true);

.....................................................

        // Stage
        Scene scene = new Scene(bp, 500, 140);
        dialog.setScene(scene);
        dialog.show();

    }

按ENTER键时,按下Yes按钮。但是当我按ESCAPE时没有变化。知道为什么吗?

0 个答案:

没有答案