I want to do some actions when user goes from one tab to another, since i made my form design with Scene Builder I cannot use code mentioned here (He used TabPaneBuild
In addition to MJafar Mash answer above, you can use "selectedIndexProperty()" to get the index of the selected tab instead of "selectedItemProperty()" which gets the selected tab itself.
chatTabs.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener (){
@Override
public void changed(ObservableValue extends Number> observable, Number oldValue, Number newValue) {
int selectedIndex = newValue.intValue();
//where index of the first tab is 0, while that of the second tab is 1 and so on.
}
});
And this is the lambda expression version of it
chartTabs.getSelectionModel().selectedIndexProperty().addListener( (observable, oldValue, newValue) -> {
int selectedIndex = newValue.intValue();
//where index of the first tab is 0, while that of the second tab is 1 and so on.
});