As evident from the current layout, a considerable gap emerges, progressively expanding with the growth in frame height. My objective is to ensure that both the "Stock Arrival" and "Stock Arrival History" frames exhibit a proportional increase in height corresponding to the overall frame size augmentation.
Here is my FXML Code:
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import org.controlsfx.control.SearchableComboBox?>
<VBox alignment="TOP_CENTER" spacing="20.0" styleClass="left-form"
stylesheets="@../stylesheets/style.css" xmlns="http://javafx.com/javafx/21"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.al_makkah_traders_app.controller.StockArrivalController">
<children>
<Label text="Stock Arrival" textFill="WHITE">
<font>
<Font name="Berlin Sans FB Demi Bold" size="30.0" />
</font>
</Label>
<VBox alignment="CENTER" spacing="20.0">
<children>
<VBox styleClass="panel-view" stylesheets="@../stylesheets/style.css">
<children>
<GridPane hgap="30.0" vgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0"
prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0"
prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0"
prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<children>
<Label text="Order No:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="Product Code:" GridPane.rowIndex="1">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="Arrived Quantity:" GridPane.rowIndex="2">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="Warehouse Quantity:" GridPane.rowIndex="3">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="Shop Quantity:" GridPane.columnIndex="2">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="Quantity Left:" GridPane.columnIndex="2"
GridPane.rowIndex="1">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="Vehicle No:" GridPane.columnIndex="2"
GridPane.rowIndex="2">
<font>
<Font size="15.0" />
</font>
</Label>
<Label text="Driver No:" GridPane.columnIndex="2"
GridPane.rowIndex="3">
<font>
<Font size="15.0" />
</font>
</Label>
<SearchableComboBox fx:id="orderNoComboBox"
promptText="Select Order No" GridPane.columnIndex="1" />
<SearchableComboBox fx:id="productCodeComboBox"
promptText="Select Product" GridPane.columnIndex="1"
GridPane.rowIndex="1" />
<TextField fx:id="arrivedQuantityTextField"
stylesheets="@../stylesheets/style.css" GridPane.columnIndex="1"
GridPane.rowIndex="2" />
<TextField fx:id="whQuantityTextField"
stylesheets="@../stylesheets/style.css" GridPane.columnIndex="1"
GridPane.rowIndex="3" />
<TextField fx:id="shQuantityTextField"
stylesheets="@../stylesheets/style.css" GridPane.columnIndex="3" />
<TextField fx:id="leftQuantityTextField"
stylesheets="@../stylesheets/style.css" GridPane.columnIndex="3"
GridPane.rowIndex="1" />
<TextField fx:id="vehicleNoTextField"
stylesheets="@../stylesheets/style.css" GridPane.columnIndex="3"
GridPane.rowIndex="2" />
<TextField fx:id="driverNoTextField"
stylesheets="@../stylesheets/style.css" GridPane.columnIndex="3"
GridPane.rowIndex="3" />
</children>
</GridPane>
<HBox alignment="TOP_RIGHT" spacing="20.0">
<children>
<Button mnemonicParsing="false" text="Confirm" />
</children>
<padding>
<Insets bottom="20.0" right="20.0" />
</padding>
</HBox>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</VBox>
<Label text="Stock Arrival History" textFill="WHITE">
<font>
<Font name="Berlin Sans FB Demi Bold" size="30.0" />
</font>
</Label>
<VBox styleClass="panel-view" stylesheets="@../stylesheets/style.css">
<children>
<HBox alignment="CENTER_LEFT" spacing="20.0">
<children>
<TextField fx:id="searchTextField" styleClass="text-field"
stylesheets="@../stylesheets/style.css" />
<Button mnemonicParsing="false" text="Search" />
</children>
<VBox.margin>
<Insets bottom="20.0" left="20.0" top="20.0" />
</VBox.margin>
</HBox>
<VBox>
<VBox.margin>
<Insets bottom="20.0" left="20.0" right="20.0" />
</VBox.margin>
<children>
<TableView fx:id="stockArrivalTableView"
stylesheets="@../stylesheets/style.css">
<columns>
<TableColumn prefWidth="75.0" text="Order No">
<cellValueFactory>
<PropertyValueFactory property="orderNo" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Arrival Date">
<cellValueFactory>
<PropertyValueFactory property="arrivalDate" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Name">
<cellValueFactory>
<PropertyValueFactory property="productName" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Brand">
<cellValueFactory>
<PropertyValueFactory property="brandName" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Dealer">
<cellValueFactory>
<PropertyValueFactory property="companyName" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Quantity">
<cellValueFactory>
<PropertyValueFactory property="quantity" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Warehouse Q">
<cellValueFactory>
<PropertyValueFactory property="warehouseQuantity" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Shop Q">
<cellValueFactory>
<PropertyValueFactory property="shopQuantity" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Quantity Left">
<cellValueFactory>
<PropertyValueFactory property="leftQuantity" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Vehicle No">
<cellValueFactory>
<PropertyValueFactory property="quantity" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Driver No">
<cellValueFactory>
<PropertyValueFactory property="quantity" />
</cellValueFactory>
</TableColumn>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</VBox>
</children>
<VBox.margin>
<Insets bottom="20.0" />
</VBox.margin>
</VBox>
</children>
<VBox.margin>
<Insets left="30.0" right="30.0" />
</VBox.margin>
</VBox>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
</VBox>```
Setting VBox child grow priorities
Tell the VBox
children to grow with Priority.SOMETIMES
or Priority.ALWAYS
.
In FXML, set this attribute on a child of the VBox.
VBox.vgrow="SOMETIMES"
OR, in Java code, call the VBox.setVgrow
API.
VBox.setVgrow(vboxChildNode, Priority.SOMETIMES);
Sets the vertical grow priority for the child when contained by a vbox. If set, the vbox will use the priority value to allocate additional space if the vbox is resized larger than its preferred height. If multiple vbox children have the same vertical grow priority, then the extra space will be split evenly between them. If no vertical grow priority is set on a child, the vbox will never allocate any additional vertical space for that child.
Minimal Example
The example below demonstrates two resizable panes in a VBox
, both with the vertical growth parameter set to grow sometimes. The constraints are set on each child of the VBox
that you want to automatically resize vertically.
The example exhibits these behaviors requested in the question:
example.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Pane style="-fx-background-color: palegreen;" VBox.vgrow="SOMETIMES" />
<Pane style="-fx-background-color: lightblue;" VBox.vgrow="SOMETIMES" />
</children>
</VBox>
Screenshots for the layout were taken from a SceneBuilder preview window.
Initial state:
After dragging the window border to resize the window: