I must write method, which will get my string(showing hours separated with commas), and return ListProperty of Strings. In my constructor I have
this.showingHour = new SimpleListProperty<String>();
I wanted to use method from this topic: https://stackoverflow.com/a/7488676/4750111
List<String> items = Arrays.asList(str.split("\\s*,\\s*"));
But it will create ArrayList. Is there function like this, but for ListProperty?
You can do
ListProperty<String> list = new SimpleListProperty<(
FXCollections.observableArrayList(str.split("\\s*,\\s*")));
As an aside, do you really need a ListProperty
? I've never found a use for it; I find just using a regular ObservableList
and registering listeners with it is enough. The arguments to SimpleListProperty
above, i.e.
FXCollections.observableArrayList(str.split("\\s*,\\s*"))
gives you an observable list with the elements you need.