【问题标题】:JavaFX 2 and Internationalization loading properties filesJavaFX 2 和国际化加载属性文件
【发布时间】:2016-09-20 23:14:37
【问题描述】:

如何加载多个 ResourceBundle 文件我有多个 fxml 文件,并且为每个文件创建了一个属性文件,例如:top.fxml top.properties 如何加载所有属性文件?

我尝试了类似的方法,但它不起作用

    Locale locale = new Locale("fr", "FR");
    ResourceBundle bundle = ResourceBundle.getBundle("i18n.bottom", locale);
    ResourceBundle bundle2 = ResourceBundle.getBundle("i18n.top", locale);

    FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
    loader.setResources(bundle);
    loader.setResources(bundle2);
    Parent root = loader.load();

【问题讨论】:

    标签: java javafx-2 resourcebundle properties-file


    【解决方案1】:

    我没有尝试过,但它应该就像每次加载之前设置捆绑一样简单:

    FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
    loader.setResources(bundle);
    Parent firstBundleRoot = loader.load();
    loader.setResources(bundle2);
    Parent secondBundleRoot = loader.load();
    

    请注意,这假设您正在尝试为不同的捆绑包生成多个节点树,每个节点树都由不同的捆绑包文本自定义(这可能不是您想要的)。

    我确实感觉我可能遗漏了您的问题中的某些内容...


    也许您正在尝试执行以下操作?

    我认为这是一种创建某种大型资源包的解决方案,其中包括来自各种资源包的合并资源。因此,如果是这种情况,您可以先合并捆绑包,然后单独加载 FXML时间导致单个根窗格。

    FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
    loader.setResources(merge(bundle1, bundle2));
    Parent root = loader.load();
    

    merge(bundle1, bundle2) 是您根据链接问题中的答案自行开发的一些功能。

    【讨论】:

    • 谢谢我需要尝试,但第二个解决方案似乎是一个不错的解决方案
    猜你喜欢
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多