使用 NetBeans。我需要有关在 FXML 文件中定义内部类的语法的帮助。
示例类,其中 Bar 是 Foo 的内部类:
public class Foo {
//... Foo stuff
public class Bar {
//... Bar stuff
}
}
在 FXML 文件中,我想使用外部类和内部类。外部类 Foo 被识别,但内部类出现“类不存在:Foo.Bar”。
示例 FXML:
<?import customcontrol.*?>
<Region>
<Foo name="thebigfoo" />
<Foo.Bar name ="inner"/>
</Region>
P.S 这是第一篇文章,所以我希望问题格式正确:)
最佳答案
将内部类设置为静态类(不与 Foo 的实例关联):
public class Foo {
//... Foo stuff
public static class Bar {
//... Bar stuff
}
}
关于JavaFX 在 FXML 中定义内部类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29587404/