A couple of classes for making custom table cells

This commit is contained in:
Sarah Gerweck 2016-06-04 00:34:06 -07:00
parent fd040af74f
commit 0f3361017d
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package org.gerweck.scalafx.util.control
import scalafx.geometry.Pos
import scalafx.scene.control.TableCell
class CenteredTextCell[A, B] extends TableCell[A, B](new GenericCell[A, B]) {
alignment = Pos.Center
}

View File

@ -0,0 +1,22 @@
package org.gerweck.scalafx.util.control
class GenericCell[A, B] extends javafx.scene.control.TableCell[A, B] {
def handleItemUpdate(item: B) = {
text = item.toString
}
override def updateItem(item: B, empty: Boolean) = {
super.updateItem(item, empty)
if (empty || item == null) {
text = null
graphic = null
} else {
handleItemUpdate(item)
}
}
final def text = getText()
final def text_=(s: String) = setText(s)
final def graphic = getGraphic()
final def graphic_=(g: javafx.scene.Node) = setGraphic(g)
}