In addition to MJafar Mash 's answer above, you can use " selectedIndexProperty() " to get the index of the selected tab instead of " selectedItemProperty() ", which itself gets the selected tab.
chatTabs.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number> (){ @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { int selectedIndex = newValue.intValue();
And this is the lambda expression version of this
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. });
Wilson
source share