JAVAFX。如何使用FXML编辑TableViewCell?
问题描述:
我想只使用fxml制作TableViewCell。我该怎么做。JAVAFX。如何使用FXML编辑TableViewCell?
现在我有DuplicateFileInfo
class DuplicateFileInfo(var id: Long, var path: String, var editableField: String?) {}
模型类和我有TableView中
<TableView AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
editable="true"
layoutX="121.0" layoutY="6.0" fx:id="duplicatesList">
<columns>
<TableColumn prefWidth="300.0" text="%file.filename" fx:id="fileNameColumn" editable="false">
<cellValueFactory>
<PropertyValueFactory property="path" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="150.0" text="%file.EditableField" fx:id="editableColumn">
<cellValueFactory>
<PropertyValueFactory property="editableField" />
</cellValueFactory>
<cellFactory>
<TextFieldTableCell fx:factory="forTableColumn" />
</cellFactory>
</TableColumn>
</columns>
</TableView>
在这种情况下,我有可编辑的表格视图。但编辑完成后,该值不会设置为模型。 是否有可能使这项工作没有codding?
答
感谢James_D 我可以得到结果。
与科特林模型类应该是这样的
class DuplicateFileInfo(id: Long, path: String, shouldBeDeleted: Boolean) {
private val id: LongProperty
private val path: StringProperty
private val shouldBeDeleted: BooleanProperty
init {
this.id = SimpleLongProperty(id)
this.path = SimpleStringProperty(path)
this.shouldBeDeleted = SimpleBooleanProperty(shouldBeDeleted)
}
fun getId(): Long {
return id.get()
}
fun idProperty(): LongProperty {
return id
}
fun setId(id: Long) {
this.id.set(id)
}
fun getPath(): String {
return path.get()
}
fun pathProperty(): StringProperty {
return path
}
fun setPath(path: String) {
this.path.set(path)
}
var isShouldBeDeleted: Boolean
get() = shouldBeDeleted.get()
set(shouldBeDeleted) = this.shouldBeDeleted.set(shouldBeDeleted)
fun shouldBeDeletedProperty(): BooleanProperty {
return shouldBeDeleted
}
override fun toString(): String {
val sb = StringBuffer("DuplicateFileInfo{")
sb.append("id=").append(id.get())
sb.append(", path=").append(path.get())
sb.append(", shouldBeDeleted=").append(shouldBeDeleted.get())
sb.append('}')
return sb.toString()
}
}
不是没有适当地或可替换地使用一个适当的'onEditCommit'处理程序,它需要被太编码codddddddddddding的项目类。 – fabian
但它很愚蠢。 我可以在不编码的情况下阅读财产。我可以在不编码的情况下编辑单元格。但是我不能在没有编码的情况下编辑结果。 –
@AlexeyVashchenkov如果您在[JavaFX属性模式](http://www.oracle.com/pls/topic/lookup?ctx=javase80&id=JFXBD107)之后编写模型类'DuplicateFileInfo',那么工厂的默认实现你正在使用将工作。 –