Java FX:如何使用 FXML 设置列约束属性
问题:
你有一个带 TableView 的 Java FXML 文件文档,想在 fxml 文档中设置此 TableView 的 columnResizePolicy。
解决方案
javafx_tableview_fxml_example.xml
<?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>不要被 netbeans 搞混,它将此行
javafx_tableview_fxml_error.xml
<TableView fx:constant=”CONSTRAINED_RESIZE_POLICY” />标记为错误(常量 'CONSTRAINED_RESIZE_POLICY' 未为 'TableView' 定义)。
Check out similar posts by category:
Allgemein
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow