0

I am developing a javafx application which has a ListView supported by an ObservableList.

@FXML
private ListView<String> taggedQueriesResultsList;
private ObservableList<String> searchResultsList = FXCollections.observableArrayList();

The ObservableList is updated with data, say list.add("something"), by a scheduled task using Executors.newSingleThreadScheduledExecutor(). However the scheduled task never runs after the first time. The UI is updated after the first run. I have noticed that if I comment out the line list.add("something") the task runs periodically as scheduled.

I think this is some synchronisation issue but not sure. Please help me understand what is going on and how to resolve the issue.

Kiran Mohan
  • 2,696
  • 6
  • 36
  • 62

2 Answers2

1

Ensure that you always update the GUI from the application thread. See http://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm

For a thread safe ObservableCollection, see here: Fast performing and thread safe observable collection

Community
  • 1
  • 1
Tarik
  • 10,810
  • 2
  • 26
  • 40
  • 2
    the second link to Fast performing and thread safe observable collection is for c#. this question is regarding java. – Kiran Mohan Jul 11 '13 at 08:36
0

An example where is created a synchronized Observable list:

newSeries = new XYChart.Series<>();
ObservableList<XYChart.Data<Number, Number>> listaSerie;
listaSerie = FXCollections.synchronizedObservableList(FXCollections.observableList(new ArrayList<XYChart.Data<Number, Number>>()));
newSeries.setData(listaSerie);
Raul
  • 465
  • 5
  • 16