Hey guys I am new to Scalafx and I am trying to create a tableview that have the ability to be editable each cells and with a change color of a cell when it has been edited, I check the examples and some code for it but still I don't figure out how to do it, I check the javafx examples but what they use is the overriding of the method updateItem in TableCell class, however this method is not implemeted in scalafx :
this is what saids in the Cell.scala class
// TODO: implement updateItem(T item, boolean empty) // might be difficult since updateItem is a protected method which needs to be defined in the delegate's class
Any help or orientation is more than welcome. Thanks in advance and sorry if is a silly question.
My approach so far is to set a CellFactory to columns as in the javafx but I got stock in the implement updateItem in scalaFX
Hello Erwin,
ScalaFX encourages
composition over inheritance. In this case, as you mentioned,
use CellFactory to
customize your table. There is an example of customizing a table
using CellFactory,
including colors in the cells, in ScalaFX FAQ: Custom
cells. Take look and let me know if you need additional
information.
Jarek
There is no need to
overwrite updateItem(),
though if you really want to do that it is possible too. First
without it. You simply add the code you need to the change
handler:
cellFactory = {
_ => new TableCell[Person, Color] {
item.onChange { (_, _, newColor) =>
graphic = new Circle {fill = newColor; radius = 8}
// Set cell background color
style = "-fx-background-color: yellow"
}
}
}
If you really want to
use updateItem() you
will need to extend JavaFX TableCell
class rather than ScalaFX class:
cellFactory = {
_ => new javafx.scene.control.TableCell[Person, Color] {
override def updateItem(item: Color, empty: Boolean) = {
super.updateItem(item, empty)
val g = new Circle {fill = item; radius = 8}
setGraphic(g)
setStyle("-fx-background-color: yellow")
}
}
}
Overwriting JavaFX
classes is not as clean as using ScalaFX API, but possible. Note
that within JavaFX class you will need to use JavaFX API to
avoid issues, so you have setGraphic(...)
instead of graphic = ....
Also remember to add import
scalafx.Includes._ to avoid some explicit conversions
between JavaFX and ScalaFX types.
Jarek
--
You received this message because you are subscribed to the Google Groups "ScalaFX Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalafx-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
item.onChange { (_, _, newvalue) => var newStyle = "" if (newvalue != "" && newvalue != null && newvalue == "!!!") newStyle = "-fx-background-color: red"