简体   繁体   English

如何更改未选中 JavaFX ListCell 的背景颜色

[英]How to change background color of unselected JavaFX ListCell

So I use a JFX ListView to display all the connected friends.所以我使用 JFX ListView来显示所有连接的朋友。 I've changed the background colors of the cells.我已经更改了单元格的背景 colors。 But on border color i cant find.但在边框颜色上我找不到。 You can easily see it, if you control+click an already selected row, it deselects it and then you can see the two blue border colors.你可以很容易地看到它,如果你控制+单击一个已经选择的行,它会取消选择它,然后你可以看到两个蓝色边框colors。 How do I change this so it fits with the rest of the background???如何更改它以使其适合背景的 rest ???

This is the css that changes the colors.这是更改 colors 的 css。

.list-cell {
    -fx-border-width: 2 0 2 0;
    -fx-border-color:#37474f;
}
.list-cell:even:hover {
    -fx-border-color:linear-gradient(to left, #DF1721, #cd005f) ;
}
.list-cell:odd:hover {
    -fx-border-color:linear-gradient(to left, #DF1721, #cd005f) ;
}
.list-cell:even:pressed {
    -fx-fill: linear-gradient(to left, #9c1017, #8f0042);
}
.list-cell:odd:pressed {
    -fx-fill: linear-gradient(to left, #9c1017, #8f0042);
}
.list-cell:hover:empty {
    -fx-border-color:#37474f;
}

.list-cell:hover:selected {
    -fx-border-color:#ff4d4d;
}
.list-cell:selected {
    -fx-background-color: #4b5960;
    -fx-border-color:#ff4d4d;
}

So here you can see an unselected ListView所以在这里你可以看到一个未选中的ListView

Its the -fx-background-insets that causing the blue lines when focused.它的 -fx-background-insets 在聚焦时会导致蓝线。 Include the below code to fix it.包括下面的代码来修复它。

.list-cell:focused {
    -fx-background-insets:0px;
}

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

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