使用Afterburner.fx设置和更改资源包

时间:2016-06-28 17:13:54

标签: java javafx resourcebundle

我正在尝试使用Afterburner.fx(https://github.com/AdamBien/afterburner.fx/)在JavaFX中创建多语言软件。我无法理解是否有办法设置或注入Afterburner视图使用的资源包,也没有办法让不同的资源包到不同的视图并在运行时更改资源包。

在简单的javafx中,可以为fxml视图设置资源包,如下例所示,但是如何使用afterburner进行此操作?

private void loadView(Locale locale) {
try {
  FXMLLoader fxmlLoader = new FXMLLoader();

  // Here, just the resource bundles name is mentioned. You can add support for more languages
  // by adding more properties-files with language-specific endings like
  // "E_13_Internationalization_fr.properties".
  fxmlLoader.setResources(ResourceBundle.getBundle("E_13_Internationalization", locale));

  Pane pane = (BorderPane) fxmlLoader.load(this.getClass().getResource("/E_13_Internationalization.fxml").openStream());
  borderPane.setCenter(pane);
} catch (IOException ex) {
  ex.printStackTrace();
}

}

1 个答案:

答案 0 :(得分:3)

加载#The columns we want to take the max of cols <- c("col1","col2","col3") df$col4 <- names(df)[names(df) %in% cols][max.col(df[,cols],ties.method="first")] col1 col2 col3 id col4 1 10 20 20 100 col2 2 20 10 10 100 col1 3 30 10 10 100 col1 afterburner.fx从视图类的包名+名称构建bundleName,例如:

ResourceBundle

用于packagename.ExampleView -> packagename.example //('View' at the ending gets removed) packagename.ExampleApp -> packagename.exampleapp

遵循该约定,您必须为每个视图创建一个单独的resourceBundle,并将其放在相应的视图包中。

如果要为所有视图使用不同的命名模式或单个resourceBundle,可以在调用ResourceBundle.getBundle(name)之前设置resourceBundle,然后使用更新的resourceBundle初始化exampleView.getView()

FMXLLoader

https://github.com/AdamBien/afterburner.fx/blob/master/src/main/java/com/airhacks/afterburner/views/FXMLView.java