title: Not loading children nodes in layout javafx
body: <p>I'm trying to do a simple startup window for my application. </p>
  
  <pre><code>    ClassLoader cachingClassLoader = new MyClassLoader(FXMLLoader.getDefaultClassLoader());
      URL resource = MainApp.class
              .getResource("/startupWindow.fxml").toURI().toURL();
      FXMLLoader loader = new FXMLLoader(resource);
      loader.setClassLoader(cachingClassLoader);
      BorderPane rootLayout = (BorderPane) loader.load();
  
      scene = new Scene(rootLayout,512,384);
  
      this.primaryStage.initStyle(StageStyle.UNDECORATED);
      this.primaryStage.setTitle(TITLE);
      this.primaryStage.setScene(scene);
      this.primaryStage.show();
  
       //configuration main layout and add it to the stage
  </code></pre>
  
  <p>Unfortunately, after the start, application shows up startup window, however without any content. Throughout the loading of the main layout the startup window content is empty. Besides I had no exceptions.</p>
  
  <p>I noticed that the problem with the content loading occurs when additional code is after the calling primaryStage.show(). And a content of layout is rendered at the end of additional code, for example:</p>
  
  <pre><code>    this.primaryStage.setScene(scene);
      this.primaryStage.show();
  
      Thread.sleep(2000L);
      // Content is displayed,( after 2 seconds ).
  </code></pre>
  
  <p>I have no idea how to make it work. Any advices will be helpful.</p>
  
  <p>EDIT:</p>
  
  <p>The issue I'm actually facing is create a startup window while loading Spring application context. I've been trying to create application context in separate Thread and it just hangs up with no exception occuring. </p>
  
  <p>EDIT 2:</p>
  
  <p>After some debugging I've found an exception:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException:
  Error creating bean with name 'SomePresenter': Invocation of init method failed;
  nested exception is java.lang.IllegalStateException: 
  Not on FX application thread; currentThread = Thread-3
  </code></pre>
  
  <p>By the way, application follows MVP design pattern and Spring application context loads automatically views and presenters.</p>
  
  <p>EDIT 3:</p>
  
  <p>The piece of code where I create new thread is:</p>
  
  <pre><code>    Task loadingTask = new Task() {
      @Override
      protected ApplicationContext call() throws Exception {
          return new ClassPathXmlApplicationContext("./spring/application_context.xml");
      }
  };
  
  loadingTask.setOnSucceeded(event -&gt; {
      context = (ApplicationContext)loadingTask.getValue();
      MainPresenter mainPresenter = (MainPresenter) context.getBean("MainPresenter");
      mainPresenter.getView().setPrimaryStage(primaryStage);
      scene = new Scene(mainPresenter.getView(), bounds.getWidth(), bounds.getHeight());
      scene.getStylesheets().add(getClass().getResource("/styles/styles.css").toExternalForm());
      this.primaryStage.setScene(scene);
  });
  
  new Thread(loadingTask).start();
  </code></pre>