gpt4 book ai didi

Javafx TitledPane 调整标题大小

转载 作者:行者123 更新时间:2023-12-02 03:43:05 25 4
gpt4 key购买 nike

有没有办法将 TitledPane 标题的大小设置为 GridPane 的大小?

enter image description here

这是 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);

最佳答案

您可以简单地在 CSS 文件中为 TitlePane header 设置固定大小:

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

或者您可以使用Nodelookup(String)函数设置高度

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

关于Javafx TitledPane 调整标题大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36630175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com