Javafx Enter by TAB

Asked

Viewed 556 times

1

Someone knows how to change the focus with the enter key instead of tab using Javafx. I’ve researched a lot and can’t find anything about it. Only in Java.

Please someone has already done it?

2 answers

1

You can do it like this:

textfield1.setOnKeyPressed( (keyEvent) -> {  
    if(keyEvent.getCode() == KeyCode.ENTER)
        textfield2.requestFocus();  
} );

-1

Hi, you can use this method, you have to pass a Textfield list of the form, with the order in which you want to happen Focus .

public void setNextFocus(TextField... texFiels) {

    for (TextField txt : texFiels) {
        txt.setOnAction(event -> {
            if (txt.getSkin() instanceof BehaviorSkinBase)
                ((BehaviorSkinBase) txt.getSkin()).getBehavior().traverseNext();

        });
    }
}
  • Thanks but I had already managed using the Robot class if (event.getCode() == KeyCode.ENTER) {
 try {
 Robot avanca = new Robot();
 avanca.keyPress(KeyEvent.VK_TAB);
 } catch (Exception ex) {
 }
 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.