JavaFX 缩放到全屏

JavaFX scaling to Full screen

我在全屏缩放时遇到问题: 我在 Java 中用 Java 编写了一个程序 FX.The GUI 很简单,但它在缩放(到全屏)方面存在问题。

当我将图片全屏时,屏幕的中间部分没有缩放到全屏。看图 第二张图片的宽度为 1920 像素。宽度设置不正确。直到大约 1500 像素宽度,才会出现一些错误,导致无法完整显示 屏幕。

中间部分有AnchorPlane ->BorderPlane (直到这个没问题) 然后在边界平面的中间,一切都停止缩放: Border Plane Center -> HBox plane -> Border plane - 顶部为文件按钮,中间为 TextArea。 对于最大宽度和最大高度都设置了最大值 maxWidth="1.7976931348623157E308" 但它们在某个值后无法正确缩放。

这里有什么问题?

<AnchorPane id="AnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="700.0" prefWidth="900.0" xmlns:fx="http://javafx.com/fxml" fx:controller="migrationscripts.SampleController">
  <children>
    <BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <bottom>
        <TextArea fx:id="help" prefHeight="25.0" promptText="Hints of usage" wrapText="true" />
      </bottom>
      <center>
        <HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
          <children>
            <BorderPane>
              <center>
                <TextArea fx:id="prvi" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" promptText="Inuput file" wrapText="true">
                  <BorderPane.margin>
                    <Insets top="5.0" fx:id="x3" />
                  </BorderPane.margin>
                </TextArea>
              </center>
              <top>
                <BorderPane>
                  <center>
                    <TextField fx:id="labelFile1" maxWidth="1.7976931348623157E308" />
                  </center>
                  <left>
                    <Button fx:id="file1" mnemonicParsing="false" onAction="#chooseFile1" text="File1:">
                      <BorderPane.margin>
                        <Insets left="5.0" right="5.0" fx:id="x2" />
                      </BorderPane.margin>
                    </Button>
                  </left>
                </BorderPane>
              </top>
            </BorderPane>

HBox 的每个子元素上的 hgrow 属性 设置为 Priority.ALWAYS:

<HBox ...>
  <children>
    <BorderPane HBox.hgrow="ALWAYS">
      <!-- ... -->
    </BorderPane>
    <!-- ... -->
  </children>
</HBox>

根据 documentation(我的重点):

Sets the horizontal grow priority for the child when contained by an hbox. If set, the hbox will use the priority to allocate additional space if the hbox is resized larger than it's preferred width. If multiple hbox children have the same horizontal grow priority, then the extra space will be split evening between them. If no horizontal grow priority is set on a child, the hbox will never allocate it additional horizontal space if available. Setting the value to null will remove the constraint.