Tabs Tabs JavaFX Tabs Don't Update Position

I noticed that when adding and removing tabs from TabPaneit, it cannot match the position of the order of the tabs in the base list. This only happens when at least one tab is completely hidden due to the width of the parent element. Here is some code that replicates the problem:

public class TabPaneTester extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Scene scene = sizeScene();
        primaryStage.setMinHeight(200);
        primaryStage.setWidth(475);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private Scene sizeScene(){
        TabPane tabPane = new TabPane();
        tabPane.setTabMinWidth(200);
        tabPane.getTabs().addAll(newTabs(3));
        Scene scene = new Scene(tabPane);
        scene.setOnKeyPressed(e -> tabPane.getTabs().add(1, tabPane.getTabs().remove(0)));
        return scene;
    }

    private static Tab[] newTabs(int numTabs){
        Tab[] tabs = new Tab[numTabs];
        for(int i = 0; i < numTabs; i++) {
            Label label = new Label("Tab Number " + (i + 1));
            Tab tab = new Tab();
            tab.setGraphic(label);
            tabs[i] = tab;
        }
        return tabs;
    }

    public static void main(String[] args) {
        launch();
    }

}

When you press a key, it removes the first tab (at index 0) and puts it back at index 1, effectively replacing the first two tabs. However, when launched, the tabs do not actually visually change (although the tab switcher menu switches its position).

Tab Stop Off

, , ( 475 500), . , ?

+4
1

, JIRA, https://bugs.openjdk.java.net/browse/JDK-8193495.

TabPaneSkin .

, , " ". . , , (, , " "), .

removeTabs, removeTabs :

  1. .
  2. , .
    • (GROW),
      1. requestLayout requestLayout requestLayout, ,
      2. (), .
    • (NONE),
      1. requestLayout , .

, , - requestLayout ( ). requestLayout ( ), ANIMATION_SPEED = 150 []. addTabs , , , .

:

ObservableList<Tab> tabs = tabPane.getTabs();
PauseTransition p = new PauseTransition(Duration.millis(150 + 20));
scene.setOnKeyPressed(e -> {
    Tab remove = tabs.remove(0);
    p.setOnFinished(e2 -> tabs.add(1, remove));
    p.play();
});

( KeyPressed , , ).

tabPane.setStyle("-fx-close-tab-animation: NONE;");

. 15 ( KeyPressed - ).

tabHeaderArea.

+2

Source: https://habr.com/ru/post/1690189/


All Articles