Tabpane: How to change Tab by clicking the Javafx button

Asked

Viewed 631 times

0

I don’t know if I’m in the right place but go anyway, guys I started learning Javafx a little while ago and have a doubt, I was wondering how I can change Tab when I click the example button: I have two Tab that is called tab1 and tab2 I wanted to do the following, when I clicked the next button I would automatically go to tab2 I don’t know if this is possible will someone help me please.

  • Using the right/left arrow already switches the tabs no?

  • exchange yes, but what I wanted to do was create a method referencing a button, instead of clicking the arrow to direct or left I wanted when the user clicked on the form button to change tab

1 answer

0


To do this the code is as follows:

// Desabilita a mudança de tab através das setas direcionais
tabpane.setFocusTraversable(false);

// Muda a aba selecionada para 1    
next.setOnAction(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
        tabpane.getSelectionModel().select(1);
    }
});

// Retorna à primeira aba    
back.setOnAction(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
        tabpane.getSelectionModel().select(0);
    }
});

I hope it helps!

  • thanks friend was exactly what I needed you don’t know as much as helped me thank you very much, that part you wrote " tabpane.setFocusTraversable(false); " I was going to ask how it was that made to disable the function of the directional arrows and you put it in the code right away until it seems that you read my mind :) Thanks again Gustavo Fragoso.

Browser other questions tagged

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