简体   繁体   中英

Javafx TitledPane resize Header

Is there a way to size the header of the TitledPane to the size of the GridPane?

在此处输入图片说明

Here is the code for the TitledPane

        // --- GridPane container
    final Label label = new Label("N/A");
    TitledPane gridTitlePane = new TitledPane();
    GridPane grid = new GridPane();

    gridTitlePane.setStyle("-fx-background-color: #336699;");
    gridTitlePane.setPrefSize(parentGrid.getPrefWidth(),parentGrid.getPrefHeight());
    gridTitlePane.setText("Statistik");
    gridTitlePane.setExpanded(false);
    //grid.setVgap(4);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(new TextField(), 1, 0);
    grid.add(new Label("Cc: "), 0, 1);
    grid.add(new TextField(), 1, 1);
    grid.add(new Label("Subject: "), 0, 2);
    grid.add(new TextField(), 1, 2);
    grid.add(new Label("Attachment: "), 0, 3);
    grid.add(label,1, 3);
                                                    gridTitlePane.setStyle("");
    gridTitlePane.setContent(grid);

    HBox hbox = new HBox();
    //HBox.setHgrow(gridTitlePane,Priority.ALWAYS);
    //HBox.setHgrow(grid,Priority.ALWAYS);
    hbox.getChildren().setAll(gridTitlePane);

You can set a fixed size to your TitlePane header simply in a css file:

.titled-pane > .title {
    -fx-pref-height: 36.0;
}

or you can set the height using the lookup(String) function of Node

Platform.runLater(() -> {
            Pane title = (Pane) titlePane.lookup(".title");
             title.setPrefHeight(value);
             //or
             title.prefHeightProperty().bind(gridPane.heightProperty());
            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM