TabPane - initial select tab not working properly?

Ambarish Rapte ambarish.rapte at oracle.com
Wed Aug 19 18:45:31 UTC 2020


Hello Daniel,

The behavior seems like a bug to me. 
Looks like the first layout of TabHeader fails to bring the selected tab header into view.
You can report it here https://bugs.java.com/bugdatabase/ 

Reason why it works with Platform.runLater():
Wrapping the select() call inside a Platfrom.runLater() causes it to run after the stage is shown i.e. after the first layout is performed. 
It can be confirmed, by wrapping a call to System.out.println(stage.isShowing());  along with select() call  OR  by wrapping the select() call inside stage.setOnShown(); instead of Platform.runLater().

Regards,
Ambarish

-----Original Message-----
From: Daniel Peintner <daniel.peintner at gmail.com> 
Sent: Wednesday, August 19, 2020 8:47 PM
To: openjfx-dev at openjdk.java.net
Subject: TabPane - initial select tab not working properly?

All,

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 expected

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 {

    @Override
    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));
            tabPane.getTabs().add(tab);
        }

        // 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(() -> {
            tabPane.getSelectionModel().select(25);
        // });

        Scene scene = new Scene(tabPane, 600, 400);
        stage.setScene(scene);

        stage.show();
    }

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

}


More information about the openjfx-dev mailing list