Reputation: 417
I try to cancel user selection in a ListView according a condition. I tried to consume mouse clicked and mouse pressed event in ListView and ListCell but it didn't work. I don't understand why bu events occur after the selected item property change. How can I cancel the user selection?
Upvotes: 2
Views: 2460
Reputation: 6537
If I understand correctly, you want to prevent users from selecting items by clicking on it. I further suppose that you tried a solution like this:
listView.addEventHandler(MOUSE_CLICKED, click -> click.consume());
That does not prevent other click handlers from being executed. Even if it did, the internal event handler seems to be fired before your event handler, since the selected item is changed before your handler is executed.
You need to add an event filter to prevent any event handlers from being fired:
listView.addEventFilter(MOUSE_CLICKED, click -> click.consume());
Upvotes: 4