Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Question about setCellFactory with Lambda Expression/Callback?

KonradZuseApr 18 2013 — edited Apr 19 2013
SO I was looking at the ensemble example and it goes like this.

listView.setCellFactory((ListView<java.lang.Number> list) -> new ListCell());
now normally when I use Lambda it's
.someMethod((event) -> {}); 
or another param.


now when I look at the Cell Factory in ListView I get this
cellFactory
public final ObjectProperty<Callback<ListView<T>,ListCell<T>>> cellFactoryProperty
Setting a custom cell factory has the effect of deferring all cell creation, allowing for total customization of the cell. Internally, the ListView is responsible for reusing ListCells - all that is necessary is for the custom cell factory to return from this function a ListCell which might be usable for representing any item in the ListView.

Refer to the Cell class documentation for more detail.

See Also:
getCellFactory(), setCellFactory(Callback)
http://docs.oracle.com/javafx/2/api/javafx/scene/control/ListView.html#cellFactoryProperty


http://docs.oracle.com/javafx/2/api/javafx/util/Callback.html I'm not 100% sure what CallBack is used for, but it seems like anything that needs an update uses it.


Now I was googling Lambda and ListCells and got this article from Oracle



it says
Adding a Cell Factory 
ListView list = new ListView(customers);
list.setCellFactory(theList -> new MyCustomCell());
i'm not really sure what "The List" is but I'm assuming it's ListView<blahbla>

So again I want to know do I have to do "new class" each time, or can do I it right inside the parameters like using ((event) -> {});

With the callback it might be necessary to call the class(or maybe there is a way around it, but I kept getting errors late last night).


Any thoughts?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 17 2013
Added on Apr 18 2013
2 comments
2,543 views