[英]How to change TableView frame color in JavaFX?
焦點邊框着色由兩個 CSS 屬性-fx-focus-color
和-fx-faint-focus-color
。
在大多數情況下,使用-fx-focus-color
就足夠了,例如將此類添加到您的 CSS 文件中:
.table-view {
-fx-focus-color: red;
}
或直接在 Java 代碼中:
table.setStyle("-fx-focus-color: red;");
但你也可以覆蓋兩者,如:
.table-view {
-fx-focus-color: red;
-fx-faint-focus-color: white;
}
背景:
通過檢查默認樣式表modena.css :
.table-view:focused{
-fx-background-color: -fx-faint-focus-color, -fx-focus-color, -fx-control-inner-background;
-fx-background-insets: -1.4, -0.3, 1;
-fx-background-radius: 2, 0, 0;
}
它發現這些顏色在:focused
偽類中用作具有各種背景插入的背景顏色。 因此對這個偽類的修改會影響焦點邊框(例如邊框的寬度)。
注1:如果要完全去除高亮,可以將這些屬性設置為-fx-focus-color: transparent;
.
注意 2:要將相同的高亮顏色應用於每個Node
您可以使用.root { -fx-focus-color: red; }
.root { -fx-focus-color: red; }
類在你的CSS文件。
感謝Dvarga ,我能夠想出這個解決方案:
不知何故-fx-focus-color:
不能與-fx-background-insets:
結合使用以用於TableView
組件。
但是-fx-background-insets:
與-fx-faint-focus-color:
。 因此,我的 css 解決方案如下所示:
.table-view:focused {
-fx-faint-focus-color: red;
-fx-background-insets: -3, 1, 2, 1;
}
現在它的工作完美! 希望我們可以幫助未來的你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.