Instead of setting the background color for the entire cell in your css, just set the -fx-control-inner-background. Then you will have the default accent, hover and focus rings still available. Also remove the if statement around your setPriorityStyle
call of course.
If you also want to override things like the default accent (selected) color or the hover color, you can also do this as in the css below - not sure if the highlight overrides are really recommended though, guess it would depend on your app and desired user experience.
.priorityLow {
-fx-control-inner-background: palegreen;
-fx-accent: derive(-fx-control-inner-background, -40%);
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
}
.priorityMedium {
-fx-control-inner-background: skyblue;
-fx-accent: derive(-fx-control-inner-background, -40%);
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
}
.priorityHigh {
-fx-control-inner-background: palevioletred;
-fx-accent: derive(-fx-control-inner-background, -40%);
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
}
Detailed styling information for JavaFX can be found in the default caspian.css stylesheet for JavaFX 2.2 and the JavaFX 2 CSS reference guide. To find caspian.css for your version of JavaFX you can unjar jfxrt.jar
(sometimes found in the jre/lib directory).
Update
The default stylesheet for JavaFX is now named modena.css
rather than caspian.css
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…