有没有更短的方法来编写这个FXML提取物?

时间:2015-01-23 19:31:49

标签: java javafx javafx-8

布局如下:

enter image description here

感兴趣的是窗户的上半部分;它是GridPane填充标签,我添加了填充,但是......

嗯,问题很明显:

            <GridPane gridLinesVisible="false">
                <padding>
                    <Insets top="5.0" bottom="5.0" left="5.0" right="5.0"/>
                </padding>
                <columnConstraints>
                    <ColumnConstraints hgrow="SOMETIMES"/>
                    <ColumnConstraints hgrow="SOMETIMES"/>
                    <ColumnConstraints hgrow="SOMETIMES"/>
                    <ColumnConstraints hgrow="SOMETIMES"/>
                </columnConstraints>
                <rowConstraints>
                    <RowConstraints vgrow="SOMETIMES"/>
                    <RowConstraints vgrow="SOMETIMES"/>
                    <RowConstraints vgrow="SOMETIMES"/>
                    <RowConstraints vgrow="SOMETIMES"/>
                </rowConstraints>

                <!-- First column -->
                <Label text="Date:" GridPane.rowIndex="0"
                    GridPane.columnIndex="0">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>
                <Label fx:id="parseDate" GridPane.rowIndex="0"
                    GridPane.columnIndex="1">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>

                <Label text="Total parse time:" GridPane.rowIndex="1"
                    GridPane.columnIndex="0">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>
                <Label fx:id="totalParseTime" GridPane.rowIndex="1"
                    GridPane.columnIndex="1">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>

                <Label text="Parse tree depth:" GridPane.rowIndex="2"
                    GridPane.columnIndex="0">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>
                <Label fx:id="treeDepth" GridPane.rowIndex="2"
                    GridPane.columnIndex="1">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>

                <Label text="Number of rules:" GridPane.rowIndex="3"
                    GridPane.columnIndex="2">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>
                <Label fx:id="nrRules" GridPane.rowIndex="3"
                    GridPane.columnIndex="3">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>

                <!-- Second column -->
                <Label text="Total rule invocations:" GridPane.rowIndex="0"
                    GridPane.columnIndex="2">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>
                <Label fx:id="totalInvocations" GridPane.rowIndex="0"
                    GridPane.columnIndex="3">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>

                <Label text="Successful rules:" GridPane.rowIndex="1"
                    GridPane.columnIndex="2">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>
                <Label fx:id="totalSuccess" GridPane.rowIndex="1"
                    GridPane.columnIndex="3">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>

                <Label text="Global success rate:" GridPane.rowIndex="2"
                    GridPane.columnIndex="2">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>
                <Label fx:id="totalSuccessRate" GridPane.rowIndex="2"
                    GridPane.columnIndex="3">
                    <padding>
                        <Insets top="5.0" bottom="5.0" left="5.0"
                            right="5.0"/>
                    </padding>
                </Label>
            </GridPane>

为了实现我想要的目标,我必须为每个Label添加填充:/ /

我已经走过了GridPane的javadoc,找不到我现在的另一种方式,但我确信存在另一种更短,更可维护的方式。

那么,这个更短的方式是什么?

1 个答案:

答案 0 :(得分:3)

尝试将VGapHGap添加到Gridpane,而不是将Padding添加到其中的每个节点。

  

hgapProperty - 列之间水平间隙的宽度。

     

vgapProperty - 行之间垂直间隙的高度。