2 Replies Latest reply on Nov 15, 2012 8:44 AM by 973809

    Rendering problem when setting ChoiceBox items with a service

      I'm trying to prepare some examples to show various FX features when I came across this strange issue. I'm using a javafx.concurrent.Service to populate the items of a ChoiceBox. When I click the ChoiceBox to show the list of choices I only get an empty rectangle with a triangle drawn on top. It's only when I click on the triangle that the ChoiceBox gets redrawn properly. From what I could see in the debugger is that the items are there at the time when I click the ChoiceBox.
      final ChoiceBox<String> choiceBox = new ChoiceBox<>();
      ExampleService service = new ExampleService();
      service.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
           public void handle(WorkerStateEvent aEvent) {
                ObservableList<String> tempValue = (ObservableList<String>) aEvent.getSource().getValue();
      Screenshot: [url https://dl.dropbox.com/u/8978331/ChoiceBoxRenderingProblem.png]https://dl.dropbox.com/u/8978331/ChoiceBoxRenderingProblem.png
      Sample code: [url https://dl.dropbox.com/u/8978331/Example2App.java]https://dl.dropbox.com/u/8978331/Example2App.java

      Shall I write a Jira issue for that one or is it my mistake?

      I'm using 1.7.0_10-ea-b13 on Windows 7 64bit but same issue occurs on Mac OS X.

      (PS: I could also use binding to accomplish this task but unfortunately RT-22449 prevents me from doing so.)

      Edited by: Thilo on Nov 13, 2012 10:57 AM to fix the broken links
        • 1. Re: Rendering problem when setting ChoiceBox items with a service
          Looks like a bug to me. It's not related to using a service (or multithreading): the code below suffers from the same issue.
          import javafx.application.Application;
          import javafx.collections.FXCollections;
          import javafx.collections.ObservableList;
          import javafx.event.ActionEvent;
          import javafx.event.EventHandler;
          import javafx.scene.Scene;
          import javafx.scene.control.Button;
          import javafx.scene.control.ChoiceBox;
          import javafx.scene.layout.VBox;
          import javafx.stage.Stage;
          public class ChoiceBoxTest extends Application {
            public void start(Stage primaryStage) throws Exception {
              primaryStage.setTitle("Example 3");
              final ChoiceBox<String> choiceBox = new ChoiceBox<>();
              final Button populateButton = new Button("Populate");
              populateButton.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                  ObservableList<String> tempValue = FXCollections.observableArrayList();
                  for (int i = 0; i < 10; i++) {
                    tempValue.add("Item " + i);
                  // This will work:
                  // choiceBox.getItems().setAll(tempValue);
              VBox root = new VBox();
              root.getChildren().addAll(populateButton, choiceBox);
              primaryStage.setScene(new Scene(root, 300, 250));
            public static void main(String[] args) {
          For a workaround, replace
          • 2. Re: Rendering problem when setting ChoiceBox items with a service
            Thanks for the work-around. I've filed RT-26273 for this one now.