Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get VBox from Task and display content

1060225Feb 24 2014 — edited Feb 27 2014

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.

When I update the code this way:

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?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 27 2014
Added on Feb 24 2014
7 comments
265 views