【问题标题】:JavaFX css controls customizingJavaFX css 控件自定义
【发布时间】:2013-01-28 15:26:20
【问题描述】:

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

【问题讨论】:

    标签: css javafx-2 javafx fxml


    【解决方案1】:

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

    @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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      • 2023-03-14
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多