Answer the question
In order to leave comments, you need to log in
JavaFx. Is it possible to make an editable cell without code?
Is it possible to make a correctly editable cell in a table without using code?
I have a model class:
class DuplicateFileInfo(var id: Long, var path: String, var editableField: String?) {}
<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>
Answer the question
In order to leave comments, you need to log in
It's all about the model class. It must match the PropertyPattern for JavaFx.
The working class of the model with which I managed to achieve the result is as follows
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()
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question