3

Is there any way to force a ListView refresh in Javafx 2.1 without reloading the list and changing the selected value?

The observable list is made of Strings so changing their value is not feasible.

betaman
  • 1,865
  • 5
  • 25
  • 30
  • where were a lot of similar questions about tableview. E.g: http://stackoverflow.com/questions/10912690/updating-rows-in-tableview – Sergey Grinev Jun 15 '12 at 21:13
  • 1
    Yes, the problem is that I don't want to change any visible property. There should be a way to programmatically make a list update, with a single call. – betaman Jun 16 '12 at 01:23

3 Answers3

3

Try:

...
ObservableList<String> olist = ... 
ListView<String> listv = ...
...
listv.setItems(null); 
listv.setItems(olist);
mr.wolle
  • 1,148
  • 2
  • 13
  • 21
  • Thanks for the answer. I have tried it and it works, but it causes a blink in some of the fields which is annoying when you are refreshing once per second. I found another more ellaborate way of doing it that works fine for my needs. If anyone needs it, just ask so I will post it. – betaman Sep 12 '13 at 11:42
  • @betaman, please post your solution - i am stuck with the same problem :( thanks! – bennyl Feb 04 '14 at 10:38
  • 1
    @bennyl There are plenty of solutions, better than mine, in the Jira link I posted above. Choose one and take the chance to vote so they fix it in a future Javafx version. https://javafx-jira.kenai.com/browse/RT-22599 – betaman Feb 05 '14 at 16:56
  • @MustafaErdemKöşk I just posted an answer with my code. Hope it helps. – betaman Sep 02 '17 at 11:49
2

Wrapping the String values with Property like SimpleStringProperty and changing this property's value should be feasible.

Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • Thank you Uluk. That is a possible solution. But I so much wish there was some kind of "refresh" command in ListView and TableView – betaman Jun 16 '12 at 01:25
  • 2
    I just created it: http://javafx-jira.kenai.com/browse/RT-22599. Anyone that would like this feature implemented is invited to visit that address and vote for this feature. – betaman Jun 16 '12 at 08:38
0

I use:

private static final ObservableList<String> lists = FXCollections.observableArrayList();
...


synchronized(lists) {
        List<String> lsts = new ArrayList<>();
        lsts.addAll(lists);
        lists.clear();
        lists.addAll(lsts);            
    }
betaman
  • 1,865
  • 5
  • 25
  • 30