简体   繁体   中英

How do you make AnchorPane resize with the window?

I'm using Scene Builder to design a layout. The parent node is an AnchorPane, which contains a GridPane that should resize with it. The AnchorPane, however, stops resizing with the GridPane (I think). How can I make it resize as the window enlarges with a mouse drag?

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>
maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM