2016-04-14 161 views
0

有没有办法将TitledPane的标题大小调整为GridPane的大小?Javafx TitledPane调整大小标题

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

回答

2

您可以直接在CSS文件中设置一个固定大小的TitlePane头代码:

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

,或者你可以设置使用lookup(String)函数的高度为Node

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

我不能这样做'gridTitlePane.setStyle(“ - fx-width:100%”,“ - fx-height:100%”)'?我可以像运行IntelliJ idea输出窗口一样在运行时调整窗格大小吗? – alhelal