public AutocompleteMenu() { // The drop-down menu which lists suggestions happens // to capture ENTER keys. // // When user types PV name into current_field and presses ENTER, // the menu captures that ENTER key and uses it to hide the menu. // --> Need to send ENTER down to current_field. // // If user selects one of the suggested menu items // and presses enter, menu item will update the current_field // --> Need to send ENTER down to current_field _after_ // the menu item updated current_field. menu.addEventFilter( KeyEvent.KEY_PRESSED, event -> { if (event.getCode() == KeyCode.ENTER && current_field != null) Platform.runLater( () -> { if (current_field != null) Event.fireEvent(current_field, event); }); }); }