TabPane: Changing Tabs by clicking the JavaFX button

1

I do not know if I'm in the right place but it goes like this, people I started learning JavaFX a short time and I have a question, I was wondering how I can change Tab when I click on the example button: I have two Tab which is called tab1 and tab2 I wanted to do the following, when I clicked the next button I would automatically go to tab2 I do not know if this is possible will someone can help me please.

    
asked by anonymous 14.08.2017 / 23:15

1 answer

1

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!

    
15.08.2017 / 02:18