假设JavaFX CSS 不支持:enabled
基于JavaFX 8 Oracle CSS Reference我该怎么做?
Hover and Active only when not disabled
TableView
存在于我应用某种 css 的地方:
.table-row-cell:hover {
-fx-background-color:orange;
}
.table-row-cell:focused {
-fx-background-color:purple;
}
我希望(仅)在启用 TableRow
时完成上述操作。
所以 我修改了包含:enabled
伪元素的代码,但现在没有任何效果:
.table-row-cell:hover:enabled {
-fx-background-color:orange;
}
.table-row-cell:focused:enabled {
-fx-background-color:purple;
}
最后是一些小问题:
1) 如何将 :hover 与 :disabled 或 :enabled 结合使用?
->[ apply **:hover** only if the `Table-Row|Cell` is enabled. ]
2)JavaFX css是否支持:enabled?
最后但并非最不重要的:
在对上面的代码做了几次测试之后,我来到了 youtu.be/l7Pbz2l2wjE?t=138这个结果。
最佳答案
我颠倒了你的想法,而不是试图找到谁是 enabled
,为什么不寻找相反的(即 disabled
)并应用固定的样式,这样当光标进入边界时它不会改变:
.table-row-cell{
-fx-background-color:red;
}
.table-row-cell:disabled{
-fx-background-color:red; //Here you can define a fixed style
// or similar to the normal state
}
.table-row-cell:focused:disabled .text{
-fx-fill: red; // Here you define the color of the text
}
.table-row-cell:hover{
-fx-background-color:blue;
}
希望对你有所帮助,如果我理解有误,请见谅!!
关于JavaFX 仅当它们是 :enabled 时才将 css 应用于 TableRows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41097246/