0

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

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
boop
  • 5
  • 3

1 Answers1

0

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.

tbeernot
  • 2,473
  • 4
  • 24
  • 31
  • How can i get an individual togglebutton from the CalendarPicker? The dayButtons are private and i cannot find a Getter-Method – boop Mar 31 '15 at 11:48
  • The use case is: Colour every day of the calendar which depends of the type of day (e.g. weekday, weekend, public holiday, private holiday, birthday, etc.). Each togglebutton needs a type and a color. – boop Mar 31 '15 at 12:02
  • You cannot get to the buttons, that would be exposing the skin to the outside. This is not how controls in JavaFX should work. – tbeernot Apr 01 '15 at 12:30
  • About your use case; what when two types are happening on the same day, for example a holiday and birthday)? I think you are describing whole day appointments in JFXtras' Agenda control. – tbeernot Apr 01 '15 at 12:31
  • With your answer i resolve it. Each togglebutton-node of the CalendarPicker has an named ID. The invisible ones "day0"-"dayX" and the visible ones like "2015-04-30". With colorpicker.lookup("2015-04-30") i can found the node of the togglebutton and change the style with node.setStyle("-fx-base: "). – boop Apr 01 '15 at 14:31