Search code examples
javafxjfxtras

jfxtras - CalendarPicker change button color


How can I change the color of every toggle button of a CalendarPicker?
For instance, one button "red", one button "yellow" and so on.


Solution

  • You should be able to, if you can create a CSS rule for it. The toggle buttons are just toggle buttons, so they have the same CSS styleable features. So a "#mypicker .toggle-button" css rule should select them.

    However, selecting individual buttons would require the use of something like "nth-child", but I believe JavaFX does not support that. There is a backdoor; the day togglebuttons get an id assigned, "day0", "day1", ... This is irrespective of whether the button is hidden or not. https://github.com/JFXtras/jfxtras/blob/8.0/jfxtras-controls/src/main/java/jfxtras/internal/scene/control/skin/CalendarPickerControlSkin.java line 366

    But this is a shaky dependency. If you have a good use case, I can of course assign a special unique style class to each button.