cod*_*leb 1 javafx fxml javafx-8
是否可以在FXML中调整TableView的大小,其中每列的相对大小调整?我知道在代码中这是可能的,但我特意寻找FXML方法.
这是目前的做法:
<BorderPane xmlns:fx="http://javafx.com/fxml">
<fx:define>
<Double fx:id="tableViewWidth" fx:value="600"/>
</fx:define>
<center>
<TableView fx:id="expensesTableView" editable="true" prefWidth="${tableViewWidth}">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn text="Title" prefWidth="${tableViewWidth * 3}">
<cellValueFactory>
<PropertyValueFactory property="title" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Category" prefWidth="${tableViewWidth * 3}">
<cellValueFactory>
<PropertyValueFactory property="category" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Period" prefWidth="${tableViewWidth * 2}">
<cellValueFactory>
<PropertyValueFactory property="period" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Value" prefWidth="${tableViewWidth * 2}">
<cellValueFactory>
<PropertyValueFactory property="value" />
</cellValueFactory>
</TableColumn>
</columns>
</TableView>
</center>
</BorderPane>
Run Code Online (Sandbox Code Playgroud)
乘法部分似乎不起作用.
您需要删除调整大小策略,并且还要将宽度绑定TableView到某个双常量.
此外,用于绑定的一些表达式在语法上是错误的......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.cell.*?>
<BorderPane xmlns:fx="http://javafx.com/fxml">
<center>
<TableView fx:id="expensesTableView" editable="true" prefWidth="600">
<columns>
<TableColumn text="Title" prefWidth="${expensesTableView.width*0.3}">
<cellValueFactory>
<PropertyValueFactory property="title" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Category" prefWidth="${expensesTableView.width*0.3}">
<cellValueFactory>
<PropertyValueFactory property="category" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Period" prefWidth="${expensesTableView.width*0.2}">
<cellValueFactory>
<PropertyValueFactory property="period" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Value" prefWidth="${expensesTableView.width*0.2}">
<cellValueFactory>
<PropertyValueFactory property="value" />
</cellValueFactory>
</TableColumn>
</columns>
</TableView>
</center>
</BorderPane>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
595 次 |
| 最近记录: |