使用事件处理程序加载fxml文件的JavaFX 2.0失败
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用事件处理程序加载fxml文件的JavaFX 2.0失败,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1999字,纯文字阅读大概需要3分钟。
内容图文
![使用事件处理程序加载fxml文件的JavaFX 2.0失败](/upload/InfoBanner/zyjiaocheng/731/aade8a7530bd445a8e89c35d55a64184.jpg)
我正在尝试从子文件夹加载fxml,但它失败了.我有替换场景内容的行:
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;
}
我在下一个方法中使用此函数:
private void gotoLogin() {
try {
replaceSceneContent("login.fxml");
} catch (Exception ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
}
问题是我得到了下一个错误:
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)
任何人都有任何想法我需要修复,所以我可以使这个取代场景内容工作?
谢谢
解决方法:
如果你在FXML文件中定义Button的动作,如下所示:
<Button text="Login" onAction="#processLogin"/>
那么你必须在控制器类中定义一个方法,如下所示.注意processLogin的签名:
@FXML
private void processLogin(javafx.event.ActionEvent event) {
// Process Login
}
内容总结
以上是互联网集市为您收集整理的使用事件处理程序加载fxml文件的JavaFX 2.0失败全部内容,希望文章能够帮你解决使用事件处理程序加载fxml文件的JavaFX 2.0失败所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。