TabPane - initial select tab not working properly?

Daniel Peintner daniel.peintner at
Wed Aug 19 15:17:17 UTC 2020


I just stumbled over a problem which I think is a bug in JavaFX.

In a program I create several tabs and initialize a selected tab upfront.
The 'select' command works fine for the tab pane content but unfortunately
not for the header that shows the current active tab (somehow the tab
header does not move to the set index).

Note1: Only happens for indices outside the visible range
Note2: wrapping the 'select' command in Platform.runLater() works as

Please find below a simple example to reproduce the issue.
Do you consider this behavior being a bug?

I see the problem for JavaFX 8 but also for 15-ea.

Thanks for any insight,

-- Daniel


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;

public class TestManyTabs extends Application {

    public void start(Stage stage) {
        TabPane tabPane = new TabPane();

        for (int i = 0; i < 30; i++) {
            Tab tab = new Tab("Tab " + i);
            tab.setContent(new Label("Content for " + i));

        // set initial tab *outside* the visible range
        // Issue: tab header does *not* switch properly
        // Note: wrapping the following select statement in
Platform.runLater() works as expected
        // Platform.runLater(() -> {
        // });

        Scene scene = new Scene(tabPane, 600, 400);

    public static void main(String[] args) {
        Application.launch(TestManyTabs.class, args);


More information about the openjfx-dev mailing list