I want to create a class that is almost identical to the object returned by FXCollections.observableArrayList()
but with some extra functionality. My first thought was something like
public class MyObservableList implements ObservableList
{
private ObservableList list = FXCollections.observableArrayList();
public functionWhatever()
{
// whatever
}
}
but that means overriding the ~30 functions that come with ObservableList
(which seems like a hint that I'm doing something wrong).
FXCollections.observableArrayList()
returns an object of type com.sun.javafx.collections.ObservableListWrapper
, but when I extend ObservableListWrapper
I'm required to create a constructor like
MyObservableList( List arg0 )
or
MyObservableList( List arg0, Callback arg1 )
which worries me because FXCollections.observableArrayList()
doesn't accept any arguments.
I don't know how FXCollections
creates the ObservableListWrapper
object that it returns but I want MyObservableList
to be identical to the object returned by FXCollections
(plus a couple extra functions).
How do I do this?
Extend SimpleListProperty docs.oracle.com
This class provides a full implementation of a Property wrapping an ObservableList.
Notice this ctor:
public SimpleListProperty(ObservableList initialValue)
So you can:
public class MyObservableList extends SimpleListProperty
{
//constructor
MyObservableList(){
super(FXCollections.observableArrayList());
}
public functionWhatever()
{
// whatever
}
}
This way your class will be based on a ArrayList.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With