[英]Change tree-cell selected font color in JavaFX
我有一個JavaFX TreeView
並希望將選定單元格的字體顏色更改為黑色,以使其看起來像未選定的單元格。 (我嘗試過setSelectionModel(null)
但這會引發錯誤。)如果重要的話,單元格在背景圖像上具有透明背景。
CSS:
.tree-view, .tree-cell {
-fx-font: 20px "Segoe Print";
-fx-background-color: transparent;
}
.tree-cell {
-fx-background-color: transparent;
-fx-padding: 0 0 0 0;
-fx-text-fill: #000000;
}
.tree-cell:focused {
-fx-text-fill: #000000;
}
.tree-cell:selected {
-fx-text-fill: #000000;
}
.tree-cell .tree-disclosure-node {
-fx-background-color: transparent;
-fx-padding: 10 10 0 40;
}
.button {
-fx-padding: 0 10 0 10;
}
結果:(選擇“ test4”)
似乎應該將選定單元格的字體顏色設置為黑色,但這沒有發生。 CSS文件已加載並正在使用(例如,字體正確,並且我還修改了其他內容),所以這不是問題。
在單元格上設置背景色:
.myTree .tree-cell {
-fx-background-color: #0a0a0a ;
-fx-text-fill: #ffffff ;
}
如果只希望透明背景,並且選定的單元格看起來與未選定的單元格相同,則可以執行以下操作:
.tree-view {
-fx-text-background-color: black ;
-fx-background-color: transparent ;
-fx-selection-bar: transparent ;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.