I am just starting with JavaFX so please excuse if this is a dumb mistake to make.
I have a GridPane
which I want to use to have two buttons next to eachother stretch over the whole width of the window. So I created a GridPane
with one row and two collumns and added in my two buttons.
Code for that:
<GridPane id="GridPane" alignment="TOP_LEFT" disable="false" gridLinesVisible="false" hgap="5.0">
<children>
<Button mnemonicParsing="false" styleClass="add-button" text="Save" GridPane.columnIndex="0" GridPane.rowIndex="0" />
<Button mnemonicParsing="false" text="Discard" GridPane.columnIndex="1" GridPane.rowIndex="0" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
But now the Button only take up their necessary space. So I added prefWidth="Infinity"
to both of them. This results in the Secene Builder 1.1 instantly freezing. I heard that the Scene Builders were and probably are buggy so I coded it into the FXML by hand and tried to run the program. The program starts but does not open a window.
Inspection of the running process with jvisualvm
tells me that the JavaFX Application Thread is allocating huge amounts of space (for millions of ArrayList
s that get instantly garbage collected). It allocates about 1.2 GB/s. The Scene Builder in contrast seems to do about nothing when I try to open the file with it as its used heap is pretty constant at about 16MB (it also does not open a window).
Even if the prefWidth
is only added on one Button
the error happens. If I use for example prefWidth="100000000"
on both buttons I get the desired result but I feel that this is realy bad coding.
So my questions are:
- Is this an error of JavaFX?
- How to get my desired result in a nicer way?