【问题标题】:JavaFX defining inner class in FXMLJavaFX 在 FXML 中定义内部类
【发布时间】:2015-06-17 16:56:08
【问题描述】:

使用 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 这是第一篇文章,所以我希望问题格式正确:)

【问题讨论】:

    标签: java class javafx fxml


    【解决方案1】:

    将内部类设为静态类(不与 Foo 的实例关联):

    public class Foo {
        //... Foo stuff
        public static class Bar {
            //... Bar stuff
        }
    }
    

    【讨论】:

    • 改成静态还是说类不存在。
    猜你喜欢
    • 2013-11-04
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    相关资源
    最近更新 更多