Add event (action) when changing tab

1

I have a TabPane in my project that contains 3 different tabs, I would like to know how to add an event when changing "tab" in JavaFX.

For example, by clicking the "address" tab, create an event for me to add functionality to this tab.

Personally, I did like this:

It worked:)!

    @FXML private TabPane tabPane;


 tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            System.out.println("Tab Selection changed");

            labelFruto.setText(fruto.getFruto());
        }



    });
    
asked by anonymous 14.07.2015 / 20:05

1 answer

1

You can add a listener for each tab, with the code below:

tabPane.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
    @Override
    public void changed(ObservableValue<? extends Number> ov, Number oldValue, Number newValue) {
        //faz algo
    }
}); 

Source: How can I do some action when one specific Tab is selected using Javafx

    
14.07.2015 / 20:14