- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有几个实例想要加载相同的 FXML 文件以捕获一些信息。
理想情况下,这将是开发实用方法的情况,即编写一次,使用多次。
这是一个当前示例,在类中使用私有(private)
方法:
private ServiceEvent_NewController loadServiceEvent_Stage(Stage primaryStage)
{
ServiceEvent_NewController controller = null;
try
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("/View/ServiceEvent_New.fxml") );
Parent root = loader.load();
// Create the dialog Stage.
Stage dialogStage = new Stage();
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(root);
dialogStage.setScene(scene);
controller = loader.getController();
controller.setDialogStage(dialogStage);
}
catch (IOException npe)
{
String message = npe.getMessage();
System.out.println(message);
}
return controller;
}
我有一个实用程序类(public final class LM_Utility
)。
如果我尝试创建一个方法来加载 FXML,使用:
public static ServiceEvent_NewController loadServiceEvent_Stage(Stage primaryStage)
编译器提示“无法从静态上下文引用非静态方法 getClass()”
。
是否有某种方法可以创建合适的实用方法来加载此类文件,以便我可以“编写一次并使用多次”?
最佳答案
getClass()
返回该方法包含的运行时类。
如果您不需要使用相对于扩展类的位置的效果,您可以简单地替换
getClass()
与
LM_Utility.class
这是 Class
的表达式LM_Utility
的对象类,这是什么getClass()
将以非静态方法返回,因为 LM_Utility
是 final
.
当然,您可能应该将 fxml 文件的资源路径传递给该方法,并使用包含 setDialogStage
的接口(interface)或抽象类。而不是硬编码对象类型。您可以使用类型参数 <T extends ControllerInterface>
允许您使用实际 Controller 类型作为分配的目标。 (但请注意,在运行时此分配仍将有效地包含对目标类型的强制转换。)
关于javafx加载FXML文件的实用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40649607/
💡 作者: 韩信子 @ ShowMeAI 📘 机器学习实战系列 : https://www.showmeai.tech/tutorials/41 📘
网络上关于SEO的文章实在是太多了,让很多新手站长都无法判别哪些是有用的,哪些是没有用的。尤其是外链建设这一块,如果被误导了,对网站将是沉重的打击。这里我整理一下比较有用的五种链接建设的方法,供大家
项目中经常有对时间进行处理的需求,下面是一些常用的操作整理,方便以后再次使用以及做相关复习。 1.字符串转换为日期 ?
有时候你会看到很Cool的Python代码,你惊讶于它的简洁,它的优雅,你不由自主地赞叹:竟然还能这样写。其实,这些优雅的代码都要归功于Python的特性,只要你能掌握这些Pythonic的技巧,你
曾经SEO流传一句老话,内容为王外链为皇,而到现在,这句话依然作为SEO优化的基础,但很多新手SEO朋友们往往在原创内容上碰壁,在2016年自媒体模式冲击下,外链的作用越来越弱,而导致了很多SEOe
本文讲述了PHP常见错误提示含义解释。分享给大家供大家参考,具体如下: 在学习PHP的时候,经常遇到各种错误提示,今天看到这错误提示和解释感觉挺好,现转过来,供我们学习。呵呵。。。。。 1、No
在现代 v8 Javascript 中,String.prototype.slice 的算法复杂度是多少? 明确地说,我正在寻找真实世界的实用数据或经验法则。 快速测试 我试图通过在最新的 Chrom
我上过几门关于 Java 的大学类(class)。然而,这些类缺少的是一些实用的 Java 方法——或者说,作为一个整体的编程。只有在企业中才能学到的东西。 但是,由于不允许我在工作场所使用 Java
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
使用新的替代工具来改进旧的命令行工具。 在Linux/Unix系统的日常使用中,我们需要使用很多命令行工具来完成工作,以及理解和管理我们的系统,例如使用du来监视磁盘利用率、top来显示系统资
灵感来自 Haskell API Search Engine 我开始想知道在 Scala 库中查找事物名称的正确方法是什么。 例如,假设我需要一些字符串变电站,例如搜索和替换。 StringOps 没
所以我已经阅读了很多这方面的内容,所以请知道我知道像 0.6 这样的数字不能绝对准确地表示为 Java double - 但我知道有一个 double 版本表示数字 0.6 足够接近,以至于在对该数字
我有一个 Django 应用程序,可以获取近乎实时的数据(推文和投票),尽管更新平均每分钟或两分钟发生一次。但是,我们希望通过在数据出现时立即更新站点和 api 结果来显示数据。 我们可能会在这个站点
我需要一个 double[],通过跨步 y 返回一个列表,将其分成 x 元素组。非常基本...一个循环和/或一些 linq 以及所有设置。然而,我并没有在扩展方法上花费太多时间,这看起来是一些练习的不
想要了解变量在 javascript 中如何在分配不同类型的值时工作。 类型 1:字符串 bool 值 类型 2:数组对象函数正则表达式日期 目前引用了两本引起混淆的书。 let mood = "li
我想在 iPad 中打开包含宏的 xls 文件。该宏与安全相关,并且已启用 xls 文件。如果我尝试使用 UIWebview 打开该文件,则会显示加密数据错误。如果 Excel 文件中禁用了宏,那么它
我发现自己在一个包含 Lua 的 C 项目中需要一个哈希表容器。我想知道是否可以将 Lua 中的哈希表用作通用容器。我查看了 ltable.h,所有函数都需要一个 Lua 状态并且似乎与 Lua 环境
尝试使用 Meteor 1.6 运行 practicalmeteor:mocha 时,我在终端上收到以下错误 Uncaught TypeError: MochaRunner.runEverywhere
我正在读《实用Django项目》这本书。这是一本好书。不过我有几个问题: 第71页,有以下代码: from django.conf.urls.defaults import * from dj
第 183 和 184 页有以下代码: def edit_snippet(request, snippet_id): snippet = get_object_or_404(Snippet,
我是一名优秀的程序员,十分优秀!