你如何使用窗口调整AnchorPane?

时间:2017-10-28 23:49:58

标签: java javafx resize fxml gridpane

我使用Scene Builder设计布局。父节点是一个AnchorPane,它包含一个应该使用它调整大小的GridPane。然而,AnchorPane停止使用GridPane调整大小(我认为)。如何通过鼠标拖动窗口放大来调整大小?

FXML:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>


<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <children>
      <GridPane fx:id="gridPane" gridLinesVisible="true" layoutX="10.0" layoutY="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <columnConstraints>
            <ColumnConstraints hgrow="ALWAYS" maxWidth="293.0" minWidth="10.0" prefWidth="163.0" />
            <ColumnConstraints hgrow="ALWAYS" maxWidth="437.0" minWidth="10.0" prefWidth="437.0" />
         </columnConstraints>
         <rowConstraints>
            <RowConstraints maxHeight="128.0" minHeight="10.0" prefHeight="29.0" vgrow="NEVER" />
            <RowConstraints maxHeight="351.0" minHeight="10.0" prefHeight="351.0" vgrow="ALWAYS" />
         </rowConstraints>
         <children>
            <MenuBar GridPane.columnSpan="2147483647" GridPane.valignment="TOP">
               <menus>
                  <Menu mnemonicParsing="false" text="File">
                     <items>
                        <MenuItem mnemonicParsing="false" text="Close" />
                     </items>
                  </Menu>
                  <Menu mnemonicParsing="false" text="Edit">
                     <items>
                        <MenuItem mnemonicParsing="false" text="Delete" />
                     </items>
                  </Menu>
                  <Menu mnemonicParsing="false" text="Help">
                     <items>
                        <MenuItem mnemonicParsing="false" text="About" />
                     </items>
                  </Menu>
               </menus>
            </MenuBar>
            <ScrollPane fx:id="mapViewScrollPane" fitToHeight="true" fitToWidth="true" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.vgrow="ALWAYS">
               <content>
                  <ImageView fx:id="mapView" fitWidth="750.0" pickOnBounds="true" preserveRatio="true" />
               </content>
            </ScrollPane>
         </children>
      </GridPane>
   </children>
</AnchorPane>

1 个答案:

答案 0 :(得分:0)

maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"