I am working on a JavaFX 2.2 project and i want to set custom handling of the mouse (double) click event on a TreeItem. Using treeview.setOnMouseClicked i fire my code without errors but the problem is that the TreeItem, on every mouse double click, it toggles between expanded and collapsed. I suppose that this is the default behavior, but how i disable it??
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Turns out that though Bolg's answer works, it isn't strictly the "correct" way to do it, and may cause some unexpected behaviour.
The cause of this issue is described in this bug. To summarise: the default double click behaviour of a tree cell is actually precipitated by the mouse press event, so it's too late to consume the event and block it within a mouse click listener.
The reason the accepted answer works is that it doesn't filter on the mouse event type, meaning it consumes all mouse events relating to the primary button and a click count of two. This also means that the user action is processed three times, which is probably not the intended behaviour.
The fix is only a single line change to Bolg's answer, but I think it is probably better not to involve an EventDispatcher. Something like the following should work just fine:
I had the same issue and solved it in time using
EventDispatcher
.and then use this
TreeMouseEventDispatcher
for theTreeCell
: