You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change custom cellFactory assignment methods to help in correct implementation that avoids artifacts #256
JavaFX requires that custom cell factories are implemented in such a way that javafx.scene.control.Cell[T]#updateItem(T item, boolean empty) is implemented correctly. Quite from JavaFX documentation for updateItem:
It is very important that subclasses of Cell override the updateItem method properly, as failure to do so will lead to issues such as blank cells or cells with unexpected content appearing within them.
Current implementation of helper cellFactory assignment is not suitable to handle that. Consider TreeCell#cellFactory_=(v: (TreeView[T] => TreeCell[T])). Current suggestions is to use it like this:
Above implementation will results in rendering artifacts as empty cells cannot be handled correctly, the empty flag is not available. The proper way would be to extends 'javafx.scene.control.Cell':
cellFactory = _ =>new javafx.scene.control.TreeCell[Person] {
// We are deriving from JavaFX, for easier use add ScalaFX wrapper for `this`valself:TreeCell[Person] =thisoverridedefupdateItem(item: Person, empty: Boolean):Unit= {
super.updateItem(item, empty)
self.graphic =null
self.text =if (empty)
nullelse item match {
casep: Person=> p.firstName +""+ p.lastName
casenull=>null
}
}
}
This is a lot of boilerplate code. There should be a helper cellFactory assignment that would promote ability to write correct code. Mot of the boilerplate would be generated automatically, user would only handle rendering and be provided with empty flag. Consider assignment with signature:
Maybe it should be even simpler. Code for resetting graphic and text when item is null or empty would be generated automatically. A cell factory would only handle non-null items and non-empty cells:
changed the title [-]Change custom `cellFactory` assignment methods to help in correct implementation that avoids artifacts[/-][+]Change custom `cellFactory` assignment methods to help in correctly implementation that avoids artifacts[/+]on Jan 29, 2020
Activity
objektwerks commentedon Mar 18, 2017
I finally found an interim solution based on this code: https://groups.google.com/forum/#!topic/scalafx-users/b3d6y3RHao0 That said, I look forward to a clean cell factory impl for ComboBox, ListView and the like.
[-]Change custom `cellFactory` assignment methods to help in correct implementation that avoids artifacts[/-][+]Change custom `cellFactory` assignment methods to help in correctly implementation that avoids artifacts[/+]15 remaining items
WIP #256: CellFactory for ComboBox and a new demo
WIP #256: Add ScalaDoc to 'ComboBox'
WIP #256: Add color preview to the ColorSelector demo
WIP #256: CellFactory for ListView and update demo
WIP #256: CellFactory for DatePicker and new DatePickerDemo
WIP #256: CellFactory for TableColumns and update demos
WIP #256: CellFactory for TreeView, update demos, remove obsolete demos
WIP #256: Some cleanup of the examples
WIP #256: Deal with null arguments to cellFactory
WIP #256: CellFactory for TableTableColumn and update demos
WIP #256: Cleanup the examples, simplify `cellValueFactory` assignments
Update example to use new, simpler cellFactory creation