JHeut
JHeut

Reputation: 305

Is there a way to map an ObservableList of objects to an ObservableList of a single object.field?

Given

public class Person {
    public final StringProperty name = new SimpleStringProperty();
}

Is there any way to map an ObservableList<Person> to an ObservableList<String> without implementing a ListChangeListener<Person> to manually update the required list?

Upvotes: 2

Views: 95

Answers (1)

JHeut
JHeut

Reputation: 305

I've found a library which does the trick:

https://github.com/tobiasdiez/EasyBind

It provides EasyBind.map with this exact functionality with a side note that the performed mapping function is executed on every get(int index), which decreases initial setup.

EasyBind.mapBacked provides an ObservableList in which the mapping function is already applied to every item, which may be preferable for intensive mapping functions.

Upvotes: 1

Related Questions