Correct way to implement JavaFX 'SelectionModel for a view that doesn't have it

I am trying to implement MultipleSelectionModel for ControlsFX 'GridView. While researching the internet, Jonathan Giles noted that it is a bad idea to add listeners to every GridCell. This got me wondering how to notify the event selection model of such a selection, selection, etc. Before reading this, I thought that the Node used in the GridCell would consume the mouse / touch / key event and use the GridCells updateSelected . My question here is if this update applies to any listeners / models at all, or if I need to link it (somewhere) manually and I don't know how to do this at the moment.

In addition, the select models use a read-only list of observables, which creates another problem with how to bind the GridView's data (i.e. the list of items) to the select model list that I assume is used for its processes.

I could bypass the use of the select model altogether and intercept the input events at the Cell / Node level and do things like highlighting in the CellItem method while using ObservableList or 2 support to keep track of everything, and update accordingly, but that's not the best way, but all the more good. The selection model for the GridView should be the only way, so I'm here.

+3


source to share


1 answer


You don't need to use MultiSelectionModel or any other JavaFX. It is enough to use Set or List to store the nodes of your choice.



Here is an example How to select multiple Canvas components using ctrl key in javafx? with an answer from me. I think this covers your needs. If not, please indicate what you need.

+2


source







All Articles