title: JavaFX: ObservableArrayList adding elements freezes application
body: <p>In my JavaFX application I try to set <code>choicebox</code> items (around 90 string items) like this:</p>
  
  <pre><code>private fun initChoiceBox(choiceBox: ChoiceBox&lt;String&gt;, elements: List&lt;String&gt;) {
  
      val detectLabel = "Detect language"
  
      choiceBox.items = FXCollections.observableArrayList(detectLabel)
  
      choiceBox.selectionModel.selectFirst()
  
      choiceBox.items.addAll(elements) // hanging is here
  
  }
  </code></pre>
  
  <p>The method above is called from <code>javafx.concurrent.Task</code>#onSucceeded:</p>
  
  <pre><code>private fun initializeSelectLanguage() {
  
  
      val task = GetSupportedLanguagesTask()
  
      task.onSucceeded = EventHandler { _ -&gt;
  
          val value = task.value
  
          val elements = value.langs.map { it.value } // around 90 elements in my case
  
          initChoiceBox(selectLanguage, elements)
          initChoiceBox(translationLanguage, elements)
  
      }
  
      task.onFailed = EventHandler {
          println(it.source.message) // todo
      }
  
      executor.submit(task)
  }
  </code></pre>
  
  <p>How can I fix this freezing? How can I update my view then if there are too many items to insert to the view?</p>
  
  <p><strong>Update 1</strong></p>
  
  <p>I create my <code>ChoiceBoxes</code> like this (using <code>fxml</code> files):</p>
  
  <pre><code>        &lt;HBox&gt;
              &lt;StackPane&gt;
                  &lt;ChoiceBox fx:id="selectLanguage"/&gt;
              &lt;/StackPane&gt;
          &lt;/HBox&gt;
  </code></pre>
  
  <p>The root <code>StackPane</code> of the <code>fxml</code> file points to the controller class like this: </p>
  
  <p><code>fx:controller="com.pany.view.Controller"</code></p>
  
  <p>And controller initializes similar to this example:</p>
  
  <pre><code>    class Controller : Initializable, Disposeable {
  
      @FXML
      private lateinit var selectLanguage: ChoiceBox&lt;String&gt;
  
      @FXML
      lateinit var translationLanguage: ChoiceBox&lt;String&gt;
  
      private val executor = Executors.newFixedThreadPool(1)
  
      override fun initialize(location: URL?, resources: ResourceBundle?) {
          initializeSelectLanguage() // method is already posted above
      }
  
      override fun dispose() {
          executor.shutdownNow()
      }
  }
  </code></pre>