title: Loading logic for JavaFX Task
body: <p>I want to put additional logic into JavaFX Task. I use this code to load Java Object from network server.</p>
  
  <pre><code>    ...........
      Tab tabdata = new Tab();
                              Task&lt;VBox&gt; task = createLoadImagesTask(data);
                              StackPane stack = createVeiledPane(task, 120, 120);
                              runTask(task);
                              tabdata.setContent(stack);
                              AgentsDataStage.addNewTab(tabdata, newValue.getValue().toString());
      ............
  
  
  private static Task&lt;VBox&gt; createLoadImagesTask(final InternalData data)
      {
          return new Task&lt;VBox&gt;()
          {
              @Override
              protected VBox call() throws Exception
              {
  
                      TabContent contentc = new TabContent();
                      return contentc.initTestTabContentData();
  
              }
          };
      }
  
      private static void runTask(Task&lt;? extends Node&gt; task)
      {
          Thread taskThread = new Thread(task, "Task Runner");
          taskThread.setDaemon(true);
          taskThread.start();
      }
  
      private static StackPane createVeiledPane(Task&lt;? extends Node&gt; task, double prefWidth, double prefHeight)
      {
          Region veil = new Region();
          veil.setStyle("-fx-background-color: transparent");
          veil.setPrefSize(prefWidth, prefHeight);
          ProgressIndicator progress = new ProgressIndicator();
          double progressSize = Math.min(prefWidth, prefHeight);
          clampSize(progress, progressSize * 0.75);
          progress.progressProperty().bind(task.progressProperty());
          StackPane stack = new StackPane();
          stack.getChildren().setAll(veil, progress);
  
          task.setOnSucceeded(new EventHandler&lt;WorkerStateEvent&gt;()
          {
              @Override
              public void handle(WorkerStateEvent t)
              {
                  stack.getChildren().setAll(task.getValue());
              }
          });
  
          return stack;
      }
  
      private static void clampSize(Control control, double size)
      {
          control.setMinSize(ProgressIndicator.USE_PREF_SIZE, ProgressIndicator.USE_PREF_SIZE);
          control.setPrefSize(size, size);
          control.setMaxSize(ProgressIndicator.USE_PREF_SIZE, ProgressIndicator.USE_PREF_SIZE);
      }
  </code></pre>
  
  <p>I would like to add additional logic when the task took more that 10 seconds to display warning message. And also if the Task fails to display again warning message. Can you help me to improve the code?</p>