Guest User

Untitled

a guest
Dec 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. private static final String FXML_MAIN = "fxml/main.fxml";
  2. public static final String BUNDLES_FOLDER = "Locale";
  3.  
  4. private Stage primaryStage;
  5.  
  6. private MainController mainController;
  7. private FXMLLoader fxmlLoader;
  8.  
  9. private VBox currentRoot;
  10.  
  11. @Override
  12. public void start(Stage primaryStage) throws Exception {
  13. this.primaryStage = primaryStage;
  14. createGUI(LocaleManager.RU_LOCALE);
  15. }
  16.  
  17. public static void main(String[] args) {
  18. launch(args);
  19. }
  20.  
  21. @Override
  22. public void update(Observable o, Object arg) {
  23. Lang lang = (Lang) arg;
  24. VBox newNode = loadFXML(lang.getLocale()); // получить новое дерево компонетов с нужной локалью
  25. currentRoot.getChildren().setAll(newNode.getChildren()); // заменить старые дочерник компонента на новые - с другой локалью
  26. }
  27.  
  28. // загружает дерево компонентов и возвращает в виде VBox (корневой элемент в FXML)
  29. private VBox loadFXML(Locale locale) {
  30. fxmlLoader = new FXMLLoader();
  31. fxmlLoader.setLocation(getClass().getResource(FXML_MAIN));
  32. fxmlLoader.setResources(ResourceBundle.getBundle(BUNDLES_FOLDER, locale));
  33.  
  34. VBox node = null;
  35.  
  36. try {
  37. node = (VBox) fxmlLoader.load();
  38.  
  39. mainController = fxmlLoader.getController();
  40. mainController.addObserver(this);
  41. primaryStage.setTitle(fxmlLoader.getResources().getString("address_book"));
  42. } catch (IOException e) {
  43. e.printStackTrace();
  44. }
  45. return node;
  46. }
  47.  
  48. private void createGUI(Locale locale) {
  49. currentRoot = loadFXML(locale);
  50. Scene scene = new Scene(currentRoot, 300, 275);
  51. primaryStage.setScene(scene);
  52. primaryStage.setMinHeight(600);
  53. primaryStage.setMinWidth(400);
  54. primaryStage.show();
  55. }}
  56.  
  57. Exception in Application start method
  58. java.lang.reflect.InvocationTargetException
  59. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  60. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  61. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  62. at java.lang.reflect.Method.invoke(Method.java:498)
  63. at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
  64. at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
  65. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  66. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  67. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  68. at java.lang.reflect.Method.invoke(Method.java:498)
  69. at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
  70. Caused by: java.lang.RuntimeException: Exception in Application start method
  71. at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
  72. at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
  73. at java.lang.Thread.run(Thread.java:748)
  74. Caused by: java.lang.IllegalStateException: Location is not set.
  75. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
  76. at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
  77. at start.Main.loadFXML(Main.java:56)
  78. at start.Main.createGUI(Main.java:68)
  79. at start.Main.start(Main.java:33)
  80. at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
  81. at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
  82. at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
  83. at java.security.AccessController.doPrivileged(Native Method)
  84. at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
  85. at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
  86. at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  87. at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
  88. ... 1 more
  89. Exception running application start.Main
Add Comment
Please, Sign In to add comment