javacssjavafx-8

How to modify the ChoiceBox checkmark in JavaFX?


First of all, is it even possible to modify the ChoiceBox checkmark shape? Completely altering the CheckBox mark was easy enough using the CSS class (.check-box:selected .mark). However, all that I've found online for the ChoiceBox's ContextMenu's mark is that you can modify its color using -fx-mark-color within the .context-menu CSS class. I've tried several classnames to change the shape to a custom SVG to no avail.

.context-menu .menu-item:selected .mark {
    -fx-shape: "M1,1 h4 v4 h-4 v-4 Z";
}

In the following picture I've completely reskinned my JavaFX application to match Mac's native Cocoa GUI, but the menu checkmark is the only flaw that appears to be impossible to fix.

enter image description here


Solution

  • Search the modena.css stylesheet for -fx-shape. For Java 8, You will find:

    .check-menu-item:checked > .left-container > .check
    

    This is the CSS selector for checkmarks inside menu items (it also covers checks for selected items in a ChoiceBox). Define the same CSS selection path in a custom CSS stylesheet. Inside that selector, place a -fx-shape rule that defines a custom svg path for the shape you wish to use for checks.