Javafx choicebox/dropdown looses focus on keyboard down arrow and moves to next item
-
13-07-2021 - |
Frage
In a JavaFX application, I have two textboxes and three choicebox on a screen. They are all placed in vertical manner.
On navigating by keyboard TAB when focus reaches fist choicebox,if i click on keyboard Down arrow, then instead of opening the items for that choicebox, focus moves to next choicebox and displays items from it.
I tried to manually override this by creating a keypress event method on first choicebox, still the focus, moves to next choicebox.
Any solution?
Lösung
Put event filter in the parent component that contains those controls.
/**
* prevent move focus on pressing UP/DOWN
*/
pnlRadioButton.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.UP || event.getCode() == KeyCode.DOWN) {
event.consume();
}
}
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow