I have a issue how to display content from a JavaFX Task. Tested this code which displays result from Task:
Task<VBox> task = new Task<VBox>()
{
@Override
protected VBox call() throws Exception
{
TabContentInfrastructure content = new TabContentInfrastructure();
return content.initTestTabContentData();
}
};
task.run();
VBox vb = new VBox();
//GetDailySalesService service = new GetDailySalesService();
//Task<VBox> task = new GetDailySalesTask();
Region veil = new Region();
veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
veil.setPrefSize(240, 160);
ProgressIndicator p = new ProgressIndicator();
p.setMaxSize(140, 140);
//p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(task.runningProperty());
p.visibleProperty().bind(task.runningProperty());
//vb.visibleProperty().bind(service.runningProperty().not());
//tableView.itemsProperty().bind(service.valueProperty());
StackPane stack = new StackPane();
//stack.getChildren().addAll(content.initTestTabContentData(), veil, p);
System.out.println("service.valueProperty() = " + task.valueProperty());
task.setOnSucceeded(new EventHandler<WorkerStateEvent>()
{
@Override
public void handle(WorkerStateEvent t){
System.out.print("Entered setOnSucceeded**********" + t.getSource().getValue());
stack.getChildren().clear();
stack.getChildren().addAll(task.getValue());
}
});
stack.getChildren().addAll(veil, p);
tabdata.setContent(stack);
Using the above code when I click on a tree node to load object the entire application freezes for 1-2 second then I see the progress bar and finally the VBox content.
new Thread(task).start();
in order to start the heavy VBox content initialization I get null as result but the performance is very smooth.
The big question is how I can display the result from the Task into the GUI after the task is completed?