TabPane - initial select tab not working properly?
Daniel Peintner
daniel.peintner at gmail.com
Wed Aug 19 15:17:17 UTC 2020
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