简体   繁体   English

更改JavaFX TreeTableView的选择颜色

[英]Change selection color of a JavaFX TreeTableView

I'm having a little trouble regarding FX, CSS and the TreeTableView. 关于FX,CSS和TreeTableView,我遇到了一些麻烦。 I have cells containing blue Hyperlinks. 我的单元格包含蓝色超链接。 Now if the cell is selected, the background becomes blue and thus the link is practically invisible. 现在,如果选择了该单元格,则背景变为蓝色,因此该链接实际上是不可见的。 I'd now like to change the background color of selected cells using Stylesheets. 现在,我想使用样式表更改选定单元格的背景颜色。

For TreeView the following works fine: 对于TreeView,以下工作正常:

.tree-view .tree-cell:selected{
    -fx-background-color: green;
}

So analogously I tried: 因此类似地我尝试:

.tree-table-view .tree-table-cell:selected{
    -fx-background-color: green;
}

But this had no effect. 但这没有效果。 Surprisingly though I was able to change the general background color with this: 出乎意料的是,尽管我能够通过以下方式更改常规背景颜色:

.tree-table-view .tree-table-cell{
    -fx-background-color: yellow;
}

The cells were now all yellow but this is seems to override the default selection pattern as now even selected rows had a yellow background. 单元格现在全都为黄色,但这似乎覆盖了默认的选择模式,因为即使选择的行也具有黄色背景。

For me it seems as if the state selector does not apply to TreeTableView cells but I have no clue how to achieve this another way. 对我来说,状态选择器似乎不适用于TreeTableView单元,但是我不知道如何实现另一种方式。

I also tried this with the Example 15-2 from the JavaFX documentation, getting the same unsatisfying result. 我还使用JavaFX文档中的示例15-2进行了尝试,得到了同样令人不满意的结果。

I was not able to find any solution on the web as all questions seem to regard TreeViews or TableViews but not the combined TreeTableView. 我无法在网络上找到任何解决方案,因为所有问题似乎都涉及TreeViews或TableViews,而不是合并的TreeTableView。 So any hint or link to the right doc would be very helpful! 因此,任何指向正确文档的提示或链接都将非常有帮助!

Thanks in advance! 提前致谢!

PS: I am aware that one could cirumvent the problem by changing the color of the Hyperlink but there must be a way to change the cell's color, right? PS:我知道可以通过更改超链接的颜色来解决该问题,但是必须有一种更改单元格颜色的方法,对吗?

You can use the .tree-table-row-cell selector with the -fx-background-color property you mentioned: 您可以将.tree-table-row-cell选择器与您提到的-fx-background-color属性一起使用:

.tree-table-row-cell:selected {
    -fx-background-color: green;
}

在此处输入图片说明

and you can also change the border color to better fit to the filling color: 您还可以更改边框颜色以更好地适合填充颜色:

.tree-table-row-cell:selected {
    -fx-background-color: green;
    -fx-table-cell-border-color: green;
}

在此处输入图片说明

You may apply more styles to the underlying table cell by using: 您可以使用以下方法将更多样式应用于基础表格单元:

.tree-table-row-cell:selected > .tree-table-cell{
    /*enter style rules here*/
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM