FXML控制器中的静态@FXML变量 [英] Static @FXML variables in FXML Controller

查看:133
本文介绍了FXML控制器中的静态@FXML变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从javafx 8 b109升级到b116,并且我的FXML控制器类在初始化时将注入的变量设置为null.我用样本netbeans fxml应用程序尝试过.

I upgraded from javafx 8 b109 to b116 and my FXML controller class has the injected variables as null when it initializes. I tried it with the sample netbeans fxml app.

@FXML
private static Label label;

@Override
public void initialize(URL url, ResourceBundle rb) {
    label.setText("static test");
} 

问题出在static关键字上,将其删除即可.在带有静态变量的b109中,它运行良好.最初编写应用程序时,我认为静态是有意义的.它们是在应用程序加载时创建的,并且场景只有一个副本.

The problem is with the static keyword, remove that and it works. It was working fine in b109 with static variables. When writing my app initially, I figured static made sense. They're created when the application loads and there's only ever one copy of the scene.

有没有办法解决这种情况而无需重写使用静态访问的一千行代码?

Is there a way around this without rewriting a thousand lines of code that use static access?

推荐答案

无论如何,我都重构了所有内容,但并不像我想象的那么难.在寻找解决方案的过程中,我花费了大约一半的时间进行重构.

Anyway I refactored everything and it wasn't as hard as I thought. I spent about half the time refactoring as I did searching for a solution.

如果其他可怜的人也有同样的问题,我将保留这个问题.

I'll leave the question in case any other poor souls have the same problem.

这篇关于FXML控制器中的静态@FXML变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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