The anonymous inner class is not released here, causing a memory leak.
anchorPane is an AnchorPane, while grandParentButton and someButtonInsideAnchorPane are Buttons.
anchorPane.getParent().getParent().lookup("#grandParentButton").addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent e) {
if (e.getCode() == KeyCode.ENTER) {
someButtonInsideAnchorPane.requestFocus();
e.consume();
}
}
});
anchorPane is an AnchorPane, while grandParentButton and someButtonInsideAnchorPane are Buttons.
anchorPane.getParent().getParent().lookup("#grandParentButton").addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent e) {
if (e.getCode() == KeyCode.ENTER) {
someButtonInsideAnchorPane.requestFocus();
e.consume();
}
}
});