我有一个FXML文件,其中包含带有onMouseClicked属性的按钮.我没有在FXML中设置一个控制器,因为我有构造函数注入我想要提供给Controller的数据.
<Button mnemonicParsing="false" onMouseClicked="#newWidgetRequestButtonClicked" text="New Widget..." />
Run Code Online (Sandbox Code Playgroud)
我以编程方式设置Controller,我的控制器包含FXML中指定的方法.Controller函数执行,一切正常.
FXMLLoader loader = new FXMLLoader(getClass().getResource("MainView.fxml"));
MyController controller = new MyController(...);
loader.setController(controller);
Run Code Online (Sandbox Code Playgroud)
我的问题在于IntelliJ检查.fxml文件.每次出现函数引用时,它都会报告"错误:(45,54)没有为顶级元素指定控制器".我正在查看IntelliJ的检查规则,并且在JavaFX部分中没有看到此规则.同样,程序构建并运行得很好,因此它不是真正的编译错误.我想禁用此错误通知.
我怎样才能避免这个错误?