Java FX: How to set the column constraint property using FXML
Problem:
You have a Java FXML file document with a TableView and want to set the columnResizePolicy of this TableView in the fxml document.
Solution
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
<TableView>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn text="c1"/>
<TableColumn text="c2"/>
<TableColumn text="c3"/>
</columns>
</TableView>
</AnchorPane>
Don’t get confused by netbeans, which marks the line
<TableView fx:constant=”CONSTRAINED_RESIZE_POLICY” />
as an error (Constant ‘CONSTRAINED_RESIZE_POLICY’ is not defined for ‘TableView’
).