我正在寻找启动时的fxml更新 [英] I am looking for fxml update on startup

查看:90
本文介绍了我正在寻找启动时的fxml更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javafx中有onclickaction,ondragaction等等
但我找不到类似onstartupaction的东西,当应用程序启动时执行一个动作

In javafx there are onclickaction , ondragaction, etc But I cant find something like onstartupaction that perform an action when the application starts

推荐答案

请参阅 Application javadoc 应用程序生命周期的一个实例。当您的应用程序启动时,它是 start方法

See the Application javadoc for an instance of the application lifecycle. When your application starts, it's start method will be called.

fxml的初始化与应用程序启动不同,因为一个应用程序可能会多次加载许多fxml文档,每次都有一个新的控制器instantiatd和它的初始化方法调用。 @FXML控制器部分对此进行了描述FXML文档简介

Initialization of fxml is different from application startup, as one application may have many fxml documents loaded many times, each time having a new controller instantiatd and it's initialization method called. This is described in the @FXML Controllers section of the Introduction to FXML documentation.

在以下控制器中,FXMLLoader将调用initialize方法。每次加载引用控制器类的FXML文档时,加载器都会创建一个新的控制器实例并在其上调用初始化。

In the following controller, the initialize method will be invoked by the FXMLLoader. Every time it loads an FXML document referencing the controller class, the loader will create a new controller instance and invoke initialize on it.

public class MyController implements Initializable {
  @FXML private Button button;

  @FXML
  protected void initialize()
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            System.out.println("You clicked me!");
        }
    });
  }
}

这篇关于我正在寻找启动时的fxml更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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