- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 CSS 更改自定义 TreeCell 的背景颜色,但在树单元格上设置样式属性不起作用。我可以使用如下所示的 CSS 文件为树设置黄色和灰色交替单元格的样式:
.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;
}
并使用如下所示的事件处理程序更改文本的填充样式:
onDragEntered = (event: DragEvent) => {
val db = event.getDragboard
if (db.hasContent(customFormat)) {
textFill = Color.DEEPSKYBLUE
style() = "tree-cell:drag-over"
}
event.consume()
}
但树单元格的样式没有改变。
最佳答案
我最终找到了自己问题的答案。 CSS 文件现在看起来像这样:
.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;
}
我现在在填充的单元格上拖动时会得到紫红色。空单元格保持白色。为了做到这一点,我需要了解“CSS 特异性”的规则,尽管最终有可能简化完成的 CSS 文件,使每种情况都与一个选择器完全匹配。
ScalaFX 代码现在看起来像这样:
import scala.collection.JavaConversions._
// Copy the list, so that it 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 the original style by taking a copy.
oldStyleClass = styleClass.toList
// Restyle filled cells with .tree-cell.dragover:filled
// for the duration of the drag
styleClass.add("drag-over")
}
event.consume()
}
onDragExited = (event: DragEvent) => {
val db = event.getDragboard
if (db.hasContent(customFormat)) {
textFill = Color.BLACK
}
// Restore the original style.
styleClass.setAll(oldStyleClass)
event.consume()
}
在途中的某个地方,我因掉落失败而丢失了动画。否则我很高兴(但在 ScalaFX 领域有点孤独。)
关于css - 如何在 ScalaFX 中使用 CSS 设置自定义 TreeCell 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18205749/
我已经尝试了一切。我认为他们犯了一个很大的错误,没有在任何内容中提供任何对索引单元格的引用。 我可以获得菜单,但不在正确的位置。右键单击即可。 在我的 TreeView 中,我可以使用 get Key
我有一个 TreeView,上面设置了一个单元工厂。我返回的 TreeCell 显示如下: import javafx.beans.binding.StringBinding; import java
我正在尝试从 TreeView 中获取当前存在的 TreeCell 的列表。我当前的尝试如下所示: private Set getMyTreeCells(){ try { @S
我正在使用 PseudoClass 根据树单元格中数据给出的条件更改 JavaFx TreeCell 的格式。以下代码有效: public class EmfTreeCellImpl extends
首先,一些上下文:我的 JavaFX 应用程序中有一个 TreeView,带有自定义的 TreeCell 实现。此实现添加了一个 HBox 以在右侧显示标签(使用 LabeledText)和一个(或多
我想要一个可折叠的列表,所以我使用的是 TreeView,但较长的字符串会提供水平滚动条而不是自动换行。我已经尝试在 .tree-cell 类上使用 CSS 属性 -fx-wrap-text 但不幸的
我知道 TreeCell 对象是由 TreeView 使用单元工厂动态生成的。 有没有办法获取当前存在的所有 TreeCell 对象的列表? 我想我可以通过修改细胞工厂来跟踪它们。就像这样,每当我创建
这个问题在这里已经有了答案: JavaFX8 treeTableView customize collapse root item (2 个答案) 关闭 8 年前。 我正在尝试使用 CellFact
环境:JDK 7u75、Windows 8.1 x64、JavaFX2.2 示例代码: public class TreeViewSample extends Application { pu
您好,我正在尝试实现一个 TreeView,它能够通过 TreeView 中的 ContextMenu 创建新元素。不过,我希望新元素能够集中调用 startEdit() 方法并自己给它命名。有什么可
我有一个带有服装 TreeCell 的 TreeView 。树单元是定制的,如下图所示。 在右侧,我选择了“一个树单元”或“树”项目。正如您所看到的,每个单元格的左侧都有手的 ImageView 。默
我想使用 CSS 更改自定义 TreeCell 的背景颜色,但在树单元格上设置样式属性不起作用。我可以使用如下所示的 CSS 文件为树设置黄色和灰色交替单元格的样式: .tree-cell:disab
我是一名优秀的程序员,十分优秀!