I want a gridpane layout as in the attached image. Anyone know how to this or am I using the wrong layout? enter image description here

1/17/2013 11:51:27 PM

Accepted Answer

Turns out what I am trying to do requires AnchorPane and GridPane.

1/21/2013 9:24:46 PM

You can control how different rows and columns in a GridPane grow using column and row constraints.

The way to do this is to set the hgrow property of the first column to ALWAYS, and the vgrow property of the first row to ALWAYS - this means the top left cell will always expand. You can either set the other cells to fixed widths/heights, or otherwise they will expand to fit their contents and no more.

I've included an FXML example with the GridPane inside an AnchorPane, and anchored to the top, left bottom and right of the AnchorPane. This means that the GridPane will grow to fill the parent AnchorPane:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="">
    <GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <ColumnConstraints hgrow="ALWAYS" />
        <ColumnConstraints prefWidth="150" />
        <RowConstraints vgrow="ALWAYS" />
        <RowConstraints prefHeight="150" />

This results in the layout shown here, and expands to fill the parent pane:

Resulting Layout

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow