javafx - 如何在 Gridpane 中获得相同垂直尺寸的 TitledPanes? (JavaFX、场景构建器)

标签 javafx size fxml scenebuilder gridpane

我对右侧 TiteldPane 的垂直尺寸有疑问(见下图)。两个 TitledPane 都放在 GridPane 中。我希望较小的那个与左边的高度相同。我尝试将右侧 TitledPane 的 Vgrow 设置为“始终”,但没有任何反应。我还尝试对一个区域做一些事情,但没有成功。如果不给它们绝对高度,这可能吗?

感谢您提前提供的帮助。

enter image description here

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<AnchorPane xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <ScrollPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <content>
          <AnchorPane>
               <children>
                  <GridPane hgap="20.0" vgap="20.0">
                    <columnConstraints>
                      <ColumnConstraints hgrow="SOMETIMES" />
                      <ColumnConstraints hgrow="SOMETIMES" />
                    </columnConstraints>
                    <rowConstraints>
                      <RowConstraints valignment="TOP" vgrow="ALWAYS" />
                    </rowConstraints>
                     <padding>
                        <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
                     </padding>
                     <children>
                        <TitledPane animated="false" text="TitledPane">
                           <content>
                              <GridPane hgap="10.0" vgap="5.0">
                                <columnConstraints>
                                  <ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" />
                                  <ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" />
                                </columnConstraints>
                                <rowConstraints>
                                  <RowConstraints vgrow="SOMETIMES" />
                                  <RowConstraints vgrow="SOMETIMES" />
                                  <RowConstraints vgrow="SOMETIMES" />
                                    <RowConstraints vgrow="SOMETIMES" />
                                    <RowConstraints vgrow="SOMETIMES" />
                                    <RowConstraints vgrow="SOMETIMES" />
                                    <RowConstraints vgrow="SOMETIMES" />
                                </rowConstraints>
                                 <children>
                                    <Label text="Label" GridPane.halignment="RIGHT" />
                                    <Label GridPane.columnIndex="1" GridPane.rowIndex="1" />
                                    <Label text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
                                    <Label GridPane.columnIndex="1" GridPane.rowIndex="3" />
                                    <Label text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="4" />
                                    <Label GridPane.columnIndex="1" GridPane.rowIndex="5" />
                                    <TextField GridPane.columnIndex="1" />
                                    <TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
                                    <TextField fx:id="abgar10TF" GridPane.columnIndex="1" GridPane.rowIndex="4" />
                                 </children>
                              </GridPane>
                           </content>
                        </TitledPane>
                        <TitledPane animated="false" text="TitledPane" GridPane.columnIndex="1" GridPane.valignment="TOP" GridPane.vgrow="ALWAYS">
                           <content>
                              <GridPane hgap="10.0" vgap="5.0">
                                <columnConstraints>
                                  <ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" />
                                  <ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" />
                                </columnConstraints>
                                <rowConstraints>
                                  <RowConstraints vgrow="SOMETIMES" />
                                  <RowConstraints vgrow="SOMETIMES" />
                                  <RowConstraints vgrow="SOMETIMES" />
                                    <RowConstraints vgrow="SOMETIMES" />
                                </rowConstraints>
                                 <children>
                                    <Label text="Label" GridPane.halignment="RIGHT" />
                                    <Label GridPane.columnIndex="1" GridPane.rowIndex="1" />
                                    <Label text="Label" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
                                    <Label GridPane.columnIndex="1" GridPane.rowIndex="3" />
                                    <TextField GridPane.columnIndex="1" />
                                    <TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
                                 </children>
                              </GridPane>
                           </content>
                        </TitledPane>
                     </children>
                  </GridPane>
               </children>
            </AnchorPane>
        </content>
      </ScrollPane>
   </children>
</AnchorPane>

最佳答案

您必须将两个 TitlePanes 的最大高度设置为 MAX_VALUE

关于javafx - 如何在 Gridpane 中获得相同垂直尺寸的 TitledPanes? (JavaFX、场景构建器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36226699/

相关文章:

java - 如何编辑 JFXSpinner 内部文本

Java 应用程序部署失败

java - 在 Java fxml 应用程序中为动态创建的 Text 对象应用鼠标单击监听器

JavaFX:TableView 单元格像素化 ImageView - 如何撤消转换?

java - 无法使用命令行运行javafx项目

java - 如何在java中锁定Stage的大小

ios - 使用 PhoneGap(构建与 xCode)我的 iOS 应用程序可以有多大?

java - 如何从 MIB 获取 DisplayString 大小约束?

Javafx - 应用程序类可以是 Controller 类吗

java - 从javafx中的 Controller 调用其他类方法