Reputation: 2558
I would like to change handling of key pressed events for example to do something else when user press up/down arrows but when i add eventHandler by setOnKeyPressed/setOnKeyReleased i cant stop native handling of those keys.
Example:
treeView.setOnKeyPressed(new EventHandler<KeyEvent>() {
private KeyCodeCombination prevNodeKeyCombination = new KeyCodeCombination(KeyCode.UP);
private KeyCodeCombination nextNodeKeyCombination = new KeyCodeCombination(KeyCode.DOWN);
public void handle(KeyEvent event)
{
if (prevNodeKeyCombination.match(event))
{
selectPrevSibling();
}
else if (nextNodeKeyCombination.match(event))
{
selectNextSibling();
}
event.consume(); // i try to block anything that goes by
}
});
Any idea how to override native key handling, if necessary i can try extend TreeView if that helps in something?
Upvotes: 0
Views: 1059
Reputation: 2558
To override native handling of event use addEventFilter in my case it was:
treeView.addEventFilter(KeyEvent.ANY, new EventHandler<KeyEvent>() { ... }
Upvotes: 1