Search code examples
javafxdatepickercalendarfarsitime4j

How can I change the font of the Time4J CalendarPicker in JavaFX?


Is there a way to change the font of Time4J CalenderPicker in css-style?

I needed a Persian DatePicker in my program so i used Time4J CalenderPicker.

using this code i could change only the font of cells:

CalendarPicker<PersianCalendar> MyDatePicker = CalendarPicker.persianWithSystemDefaults(); 

MyDatePicker.setCellCustomizer(
            (cell, column, row, model, date) -> {
                cell.setStyle("-fx-font-family: MyFont;");
            }
    );

You can see changes in this image

I tried this code but nothing changed:

MyDatePicker.setStyle("-fx-font-family: MyFont;");

But i want to change the font of hole CalendarPicker.

enter image description here

enter image description here


Solution

  • In order to apply the changes, you need to use the following code and set new css styles for calender picker and applying the customizations.

    private CalendarPicker<PersianCalendar> MyDatePicker = CalendarPicker.persianWithSystemDefaults();
    MyDatePicker.getStylesheets().add("/MyCSS-Style.css");
    

    The following gif, demonstrates my customizations.

    enter image description here