How to style a custom TreeCell with CSS in ScalaFX? -
i want change background colour of custom treecell using css, setting style property on tree cell doesn't work. can style tree alternate yellow , grey cells css file looks this:
.tree-cell:disabled { -fx-padding: 3 3 3 3; -fx-background-color: white; } .tree-cell:selected { -fx-background-color: blue; } .tree-cell:even { -fx-background-color: yellow; } .tree-cell:odd { -fx-background-color: grey; } .tree-cell:drag-over { -fx-background-color: plum; }
and change fill style of text event handler looks this:
ondragentered = (event: dragevent) => { val db = event.getdragboard if (db.hascontent(customformat)) { textfill = color.deepskyblue style() = "tree-cell:drag-over" } event.consume() }
but style of tree cells doesn't change.
i found answer own question. css file looks this:
.tree-cell:disabled { -fx-padding: 3 3 3 3; -fx-background-color: white; } .tree-cell:selected { -fx-background-color: blue; } .tree-cell:filled:even { -fx-background-color: lightyellow; } .tree-cell:filled:odd { -fx-background-color: lightsteelblue; } .tree-cell.drag-over:filled { -fx-background-color: plum; }
i plum colour when dragging on filled cell. empty cells stay white. in order here needed understand rules of "css specificity", although possible simplify finished css file make each case match 1 selector.
the scalafx code looks this:
import scala.collection.javaconversions._ // copy list, isn't modified in place. var oldstyleclass: util.collection[string] = styleclass.tolist ondragentered = (event: dragevent) => { val db = event.getdragboard if (db.hascontent(customformat)) { textfill = color.deepskyblue // remember original style taking copy. oldstyleclass = styleclass.tolist // restyle filled cells .tree-cell.dragover:filled // duration of drag styleclass.add("drag-over") } event.consume() } ondragexited = (event: dragevent) => { val db = event.getdragboard if (db.hascontent(customformat)) { textfill = color.black } // restore original style. styleclass.setall(oldstyleclass) event.consume() }
somewhere along way lost animation failed drop. otherwise i'm happy (but lonely in scalafx-land.)
Comments
Post a Comment