JavaFX GridPane automatic sizing
<p>I'm new to JavaFX and currently I try to build a small chat window. For this purpose I got the following custom Cell Layout for my Listview.</p>

<p><a href="http://i.stack.imgur.com/WbacL.jpg" rel="nofollow">Grid</a></p>

<p>I use an outer HBox, so I can align the messages like whatsapp... (align left and right). In my GridPane I got 2 columns, the message (Label) on the left side and some other random stuff on the right side (timestamp, some small icons). Now what I need: The GridPane / left Column / Label should dynamically grow / shrink in height, depending on how long the text message is. Furthermore the minimum height should be the height of the right column. </p>

<p>Here is my .fxml for the cell: </p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;?import javafx.scene.control.Label?&gt;
&lt;?import javafx.scene.image.Image?&gt;
&lt;?import javafx.scene.image.ImageView?&gt;
&lt;?import javafx.scene.layout.AnchorPane?&gt;
&lt;?import javafx.scene.layout.ColumnConstraints?&gt;
&lt;?import javafx.scene.layout.GridPane?&gt;
&lt;?import javafx.scene.layout.HBox?&gt;
&lt;?import javafx.scene.layout.RowConstraints?&gt;

&lt;HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="50" minWidth="-Infinity" prefWidth="580.0" styleClass="theme-presets inbox-entry" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1"&gt;
   &lt;children&gt;
      &lt;GridPane prefHeight="100.0" prefWidth="452.0"&gt;
        &lt;columnConstraints&gt;
          &lt;ColumnConstraints hgrow="ALWAYS" maxWidth="359.0" minWidth="10.0" prefWidth="351.0" /&gt;
          &lt;ColumnConstraints hgrow="SOMETIMES" maxWidth="103.0" minWidth="0.0" prefWidth="101.0" /&gt;
        &lt;/columnConstraints&gt;
        &lt;rowConstraints&gt;
          &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" /&gt;
        &lt;/rowConstraints&gt;
         &lt;children&gt;
            &lt;Label fx:id="labelMessage" alignment="TOP_LEFT" prefHeight="100.0" prefWidth="286.0"  wrapText="true" /&gt;
            &lt;AnchorPane prefHeight="100.0" prefWidth="133.0" GridPane.columnIndex="1"&gt;
               &lt;children&gt;
                  &lt;ImageView fx:id="imageViewEncrypted" fitHeight="33.0" fitWidth="33.0" layoutX="4.0" layoutY="23.0" pickOnBounds="true" preserveRatio="true"&gt;
                     &lt;image&gt;
                        &lt;Image url="@../../images/key.png" /&gt;
                     &lt;/image&gt;
                  &lt;/ImageView&gt;
                  &lt;ImageView fx:id="imageViewSigned" fitHeight="42.0" fitWidth="33.0" layoutX="4.0" layoutY="50.0" pickOnBounds="true" preserveRatio="true"&gt;
                     &lt;image&gt;
                        &lt;Image url="@../../images/doublecheck.png" /&gt;
                     &lt;/image&gt;
                  &lt;/ImageView&gt;
                  &lt;Label fx:id="labelTime" layoutX="4.0" layoutY="6.0" prefHeight="17.0" prefWidth="76.0" text="Label" /&gt;
               &lt;/children&gt;
            &lt;/AnchorPane&gt;
         &lt;/children&gt;
      &lt;/GridPane&gt;
   &lt;/children&gt;
&lt;/HBox&gt;
</code></pre>

<p>EDIT: here is the working version</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;?import javafx.scene.control.Label?&gt;
&lt;?import javafx.scene.image.Image?&gt;
&lt;?import javafx.scene.image.ImageView?&gt;
&lt;?import javafx.scene.layout.AnchorPane?&gt;
&lt;?import javafx.scene.layout.ColumnConstraints?&gt;
&lt;?import javafx.scene.layout.GridPane?&gt;
&lt;?import javafx.scene.layout.HBox?&gt;
&lt;?import javafx.scene.layout.RowConstraints?&gt;

&lt;HBox maxHeight="-Infinity" maxWidth="-Infinity" prefWidth="580.0" styleClass="theme-presets inbox-entry" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1"&gt;
   &lt;children&gt;
      &lt;GridPane prefWidth="452.0"&gt;
        &lt;columnConstraints&gt;
          &lt;ColumnConstraints hgrow="SOMETIMES" maxWidth="350" /&gt;
          &lt;ColumnConstraints hgrow="SOMETIMES" /&gt;
        &lt;/columnConstraints&gt;
        &lt;rowConstraints&gt;
          &lt;RowConstraints fillHeight="true" vgrow="ALWAYS" /&gt;

        &lt;/rowConstraints&gt;
         &lt;children&gt;
            &lt;Label fx:id="labelMessage" alignment="TOP_LEFT" maxHeight="Infinity" text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." wrapText="true" /&gt;
            &lt;AnchorPane GridPane.columnIndex="1"&gt;
               &lt;children&gt;
                  &lt;ImageView fx:id="imageViewEncrypted" fitHeight="33.0" fitWidth="33.0" layoutX="43.0" layoutY="-2.0" pickOnBounds="true" preserveRatio="true"&gt;
                     &lt;image&gt;
                        &lt;Image url="@../../images/key.png" /&gt;
                     &lt;/image&gt;
                  &lt;/ImageView&gt;
                  &lt;ImageView fx:id="imageViewSigned" fitHeight="42.0" fitWidth="33.0" layoutX="80.0" layoutY="-2.0" pickOnBounds="true" preserveRatio="true"&gt;
                     &lt;image&gt;
                        &lt;Image url="@../../images/doublecheck.png" /&gt;
                     &lt;/image&gt;
                  &lt;/ImageView&gt;
                  &lt;Label fx:id="labelTime" layoutX="4.0" layoutY="6.0" prefHeight="17.0" prefWidth="76.0" text="Label" /&gt;
               &lt;/children&gt;
            &lt;/AnchorPane&gt;
         &lt;/children&gt;
      &lt;/GridPane&gt;
   &lt;/children&gt;
&lt;/HBox&gt;
</code></pre>