关闭子阶段 [英] Closing a substage

查看:58
本文介绍了关闭子阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的正是Meg在这里所说的:

What I'm trying to do I think is exactly what Meg is talking about here: JavaFX2 : Closing a stage (substage) from within itself

当我尝试实现JewelSea的答案时,我得到无法从静态上下文引用非静态方法getSource()".

When I try to implement JewelSea's answer I get the "nonstatic method getSource() cannot be referenced from a static context."

因此,我在Scene Builder中使用一个简单的控制器类创建了辅助窗口(场景),该控制器类基本上具有一个功能:将按钮绑定到close()事件处理程序.这是我的代码:

So I have my secondary window (scene) created in Scene Builder with a simple controller class that has basically one function: tie the button to a close() event handler. Here's the code I have:

public class ProductNotFoundController
    implements Initializable {

    @FXML //  fx:id="closeButton"
    private Button closeButton; // Value injected by FXMLLoader


    @Override // This method is called by the FXMLLoader when initialization is complete
    public void initialize(URL fxmlFileLocation, ResourceBundle resources) {

        closeButton.setOnAction(new EventHandler<ActionEvent> () {
            @Override
            public void handle(ActionEvent t) {
//                ProductNotFound.avisoClose();
                Node source;
                source = (Node) ActionEvent.getSource();
                Stage stage = (Stage) source.getScene().getWindow();
                stage.close();
            }
        });

    }

}

有人可以告诉我我做错了什么吗?和/或应该在哪里放置close()方法?

Can someone please tell me what I'm doing wrong? And/or where should I put the close() method?

推荐答案

t

Replace ActionEvent by t, getSource is a non-static method. jewelsea was using actionEvent the instance of the ActionEvent class.

这篇关于关闭子阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆