0
我有一個TableColumn
編碼爲:FXML:綁定到嵌套場
<TableColumn text="Nom" prefWidth="${purchasesTable.width*0.65}">
<cellValueFactory>
<PropertyValueFactory property="item.name" />
</cellValueFactory>
</TableColumn>
它TableView
的項目屬性綁定到Purchase
類的列表:
採購類:
public class Purchase {
private Item item;
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
}
我的Item
class is as foll OWS:
public class Item {
private long id;
private StringProperty name = new SimpleStringProperty();
private DoubleProperty price = new SimpleDoubleProperty();
//Getters and Setters
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public final StringProperty nameProperty() {
return this.name;
}
public final String getName() {
return this.nameProperty().get();
}
public final void setName(final String name) {
this.nameProperty().set(name);
}
}
當我添加購買到我的表名單元不會出現。我究竟做錯了什麼?是否需要我的Item
字段作爲屬性,因爲我想在其他地方使用JavaFX而不使用它們?
如果我添加其他列如何創建一個方法'setUpColumn'以避免代碼重複? –