1
votes

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>
1
How about using a BorderPane instead of the AnchorPane and ensuring HGROW and VGROW are set to always?kvr
Your anchor pane does resize to the window, assuming it is the root of the scene. However, the anchor pane has only one child node, a grid pane, and you explicitly prevent that from growing by specifying max widths for each column and max heights for each row. So the grid pane can't grow, and you see the content having a maximum size.James_D
@James_D Thanks, that fixed it! If you want you can put that as an answer I'll mark it.CptHowdyRD0

1 Answers

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