JavaFX一个组件窗口调整大小,子组件自动调整大小

时间:2019-02-07 13:20:19

标签: javafx fxml

我想调整子组件的大小。我正在按照这里的建议使用VBOX:Javafx resize components when fullscreen。我没有根据窗口宽度调整所有组件大小的运气。只有我的第一个面板会调整大小,我不知道为什么。

这是我的FXML代码:

<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" rotate="-0.0" style="-fx-background-color: ;" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="solutions.lunalabs.incubeatthor.scenes.StatusController">
    <children>
        <Pane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-background-color: #272D2D" VBox.vgrow="ALWAYS">
            <effect>
                <DropShadow />
            </effect>
            <children>
                <Pane layoutX="159.0" prefWidth="553.0" style="-fx-background-color: #272D2D;">
                    <children>
                        <Label layoutX="146.0" layoutY="14.0" text="STATUS" textFill="WHITE">
                            <font>
                                <Font name="System Bold" size="43.0" />
                            </font>
                        </Label>
                        <VBox layoutX="23.0" layoutY="66.0" prefHeight="437.0" prefWidth="469.0">
                            <children>
                                <Pane fx:id="serverStatus" prefHeight="440.0" prefWidth="469.0" style="-fx-background-color: #272D2D;" />
                                <Pane fx:id="generalStatus" prefHeight="440.0" prefWidth="469.0" style="-fx-background-color: #272D2D;">
                                    <children>
                                        <VBox prefHeight="440.0" prefWidth="469.0" />
                                    </children></Pane>
                                <Pane fx:id="sensorStatus" prefHeight="926.0" prefWidth="469.0" style="-fx-background-color: #272D2D;">
                                    <children>
                                        <VBox prefHeight="440.0" prefWidth="489.0">
                                            <children>
                                                <Pane layoutX="14.0" layoutY="14.0" prefHeight="98.0" prefWidth="549.0" style="-fx-background-color: #36393d;">
                                                    <children>
                                                        <Label layoutX="4.0" layoutY="6.0" text="Temparature" textFill="WHITE">
                                                            <font>
                                                                <Font name="System Bold Italic" size="13.0" />
                                                            </font>
                                                        </Label>
                                                        <Label fx:id="temparatureStatus" layoutY="22.0" prefHeight="73.0" prefWidth="95.0" text="0C" textFill="WHITE" translateX="3.0">
                                                            <font>
                                                                <Font name="System Bold" size="28.0" />
                                                            </font>
                                                        </Label>
                                                    </children>
                                                    <effect>
                                                        <DropShadow />
                                                    </effect></Pane>
                                            </children>
                                        </VBox>
                                    </children></Pane>
                            </children>
                        </VBox>
                    </children>
                </Pane>
            <VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity">
               <children>
                      <Pane maxHeight="1.7976931348623157E308" style="-fx-background-color: #e74c3c;">
                          <children>
                        <VBox>
                           <children>
                                    <Pane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="509.0" prefWidth="52.0" style="-fx-background-color: #34495e;" VBox.vgrow="ALWAYS">
                                        <effect>
                                            <DropShadow />
                                        </effect>
                                    </Pane>
                           </children>
                        </VBox>
                              <JFXButton fx:id="sensorBtn" alignment="BASELINE_LEFT" graphicTextGap="25.0" layoutY="130.0" onAction="#statusHandler" text="SENSORS" textFill="#c5c5c5">
                                  <font>
                                      <Font name="System Bold" size="14.0" />
                                  </font>
                                  <graphic>
                                      <FontAwesomeIconView glyphName="HEARTBEAT" size="25.0" strokeType="OUTSIDE" strokeWidth="0.0" />
                                  </graphic>
                              </JFXButton>
                              <JFXButton fx:id="generalBtn" alignment="BASELINE_LEFT" graphicTextGap="25.0" layoutX="-1.0" layoutY="77.0" onAction="#statusHandler" text="GENERAL" textFill="#c5c5c5">
                                  <font>
                                      <Font name="System Bold" size="14.0" />
                                  </font>
                                  <graphic>
                                      <FontAwesomeIconView glyphName="LEAF" size="25" strokeType="OUTSIDE" strokeWidth="0.0" />
                                  </graphic>
                              </JFXButton>
                              <JFXButton fx:id="serverBtn" alignment="BASELINE_LEFT" graphicTextGap="25.0" layoutY="183.0" onAction="#statusHandler" text="SERVER" textFill="#c5c5c5">
                                  <font>
                                      <Font name="System Bold" size="14.0" />
                                  </font>
                                  <graphic>
                                      <FontAwesomeIconView glyphName="TASKS" size="25.0" strokeType="OUTSIDE" strokeWidth="0.0" />
                                  </graphic>
                              </JFXButton>
                              <Label layoutX="54.0" layoutY="6.0" prefHeight="16.0" prefWidth="104.0" text="STATUS TAB" textAlignment="CENTER">
                                  <font>
                                      <Font name="System Bold Italic" size="13.0" />
                                  </font>
                              </Label>
                          </children>
                          <effect>
                              <DropShadow />
                          </effect>
                      </Pane>
               </children>
            </VBox>
            </children>
        </Pane>
    </children>
</VBox>

以下是调整大小前的外观图像: before window resizing

这是调整窗口大小后的图像: after window resizinh

我似乎无法弄清楚如何调整其他子元素的大小,而不仅仅是第一个面板子元素。还有如何仅垂直调整大小,以及如何同时调整两个大小?我认为它必须与Vgrow一起使用,但是我不确定如何实现它。在与GUI交互时,我目前仅使用FXML。

0 个答案:

没有答案