使用事件处理程序加载fxml文件的JavaFX 2.0失败 [英] JavaFX 2.0 loading fxml files with event handlers fails
本文介绍了使用事件处理程序加载fxml文件的JavaFX 2.0失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从子文件夹加载fxml,但它失败了。我有替换场景内容的行:
i am trying to load a fxml from a subfolder, but it fails. I have the line that make the replace scene content:
private Parent replaceSceneContent(String fxml) throws Exception {
Parent page = (Parent) FXMLLoader.load(App.class.getResource("skinFolder/fxml/"+fxml), null, new JavaFXBuilderFactory());
Scene scene = stage.getScene();
if (scene == null) {
scene = new Scene(page, 700, 450);
scene.getStylesheets().add(App.class.getResource("skinFolder/css/defaultSkin.css").toExternalForm());
stage.setScene(scene);
} else {
stage.getScene().setRoot(page);
}
stage.sizeToScene();
return page;
}
我在下一个方法中使用此函数:
I use this function in the next method:
private void gotoLogin() {
try {
replaceSceneContent("login.fxml");
} catch (Exception ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
}
问题是我遇到了下一个错误:
The problem is that i got the next errors:
javafx.fxml.LoadException: Method processLogin() does not have the correct signature for an event handler.
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(Unknown Source)
at javafx.fxml.FXMLLoader.processEndElement(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at Main.App.replaceSceneContent(App.java:115)
at Main.App.gotoLogin(App.java:108)
at Main.App.start(App.java:72)
at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)
任何人都有任何想法需要解决的问题所以我可以让这个替换场景内容起作用吗?
Anyone has any ideea what i need to fix so i can make this replace scene content to work?
谢谢
推荐答案
如果你在FXML文件中定义 Button
的动作,就像这样:
If you are defining an action of Button
in FXML file like this:
<Button text="Login" onAction="#processLogin"/>
然后你必须在控制器类中定义一个方法,如下所示。请注意 processLogin
的签名:
then you must define a method in the controller class like as following. Note the signature of processLogin
:
@FXML
private void processLogin(javafx.event.ActionEvent event) {
// Process Login
}
这篇关于使用事件处理程序加载fxml文件的JavaFX 2.0失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文