When there are more tabs in tabPane the arrow will show in the top right area, then click the arrow button and you can see the first one of tab name in the list cannot updated with the right tab name text.
Please refer to the below code, thanks~
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;
public class TabPaneTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
SimpleStringProperty tabText = new SimpleStringProperty("First Tab Name");
updateTabText(tabText);
TabPane tabPane = new TabPane();
for (int i = 0; i < 10; i++) {
Tab tab = new Tab("TabName_000000000000_" + i);
if (i == 0) {
tab.textProperty().bind(tabText);
}
tabPane.getTabs().add(tab);
}
Scene scene = new Scene(tabPane, 800, 600);
primaryStage.setScene(scene);
primaryStage.setTitle("Multiple Tabs of TabPane Test");
primaryStage.show();
}
private void updateTabText(SimpleStringProperty tabText) {
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(() -> {
Platform.runLater(() -> {
tabText.set(UUID.randomUUID().toString());
});
}, 0, 5, TimeUnit.SECONDS);
}
}
Please refer to the below code, thanks~
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;
public class TabPaneTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
SimpleStringProperty tabText = new SimpleStringProperty("First Tab Name");
updateTabText(tabText);
TabPane tabPane = new TabPane();
for (int i = 0; i < 10; i++) {
Tab tab = new Tab("TabName_000000000000_" + i);
if (i == 0) {
tab.textProperty().bind(tabText);
}
tabPane.getTabs().add(tab);
}
Scene scene = new Scene(tabPane, 800, 600);
primaryStage.setScene(scene);
primaryStage.setTitle("Multiple Tabs of TabPane Test");
primaryStage.show();
}
private void updateTabText(SimpleStringProperty tabText) {
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(() -> {
Platform.runLater(() -> {
tabText.set(UUID.randomUUID().toString());
});
}, 0, 5, TimeUnit.SECONDS);
}
}