0

我有 css 样式类:

.customTabPane {
     -fx-tab-min-height: 20;
}
.customTabPane:top *.tab-header-area {
    -fx-background-insets: 0, 0 0 1 0;
    -fx-padding: 5 0 0 0;
}

.customTabPane:top *.tab {
    -fx-padding:  0 0 0 0;
}

.customTabPane *.tab-header-background {
    -fx-background-color: red;
}

但是 *.tab-header-area, *.tab-header-background 适用于应用程序中的所有 TabPane-s,而不仅仅是“customTabPane”(tabPane.getStyleClass().add("customTabPane"))。我怎样才能解决这个问题?

4

1 回答 1

0

我已经测试了您的用例,并且 css 仅应用于具有“customTabPane”样式类的 tabpane。再次检查您的代码。

@Override
public void start(Stage primaryStage) {

    TabPane tabPane = new TabPane();
    tabPane.getStyleClass().add("customTabPane");
    tabPane.getTabs().add(new Tab("tab 1"));

    TabPane tabPane2 = new TabPane();
    tabPane2.getTabs().add(new Tab("tab 2"));

    VBox root = new VBox();
    root.getChildren().addAll(tabPane,tabPane2);

    Scene scene = new Scene(root, 300, 250);
    scene.getStylesheets().add(this.getClass().getResource("style.css").toExternalForm());

    primaryStage.setScene(scene);
    primaryStage.show();
}
于 2013-01-29T12:32:57.820 回答