JavaFX css控制自定义

时间:2013-01-28 15:26:21

标签: css javafx-2 javafx fxml

我有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"))。我该如何解决这个问题?

1 个答案:

答案 0 :(得分: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();
}