3

I would like to change Locale of JFXDatePicker to my own custom Locale like into Cyrillic more precisely Uzbek Language. I searched google but there were no good tips about what to do. enter image description here

in this DatePicker, I would like to see my own custom string instead of пн,мар 19 and so on. How I could modify JFXDatePicker into my own Locale?

Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
Jahongir Sabirov
  • 460
  • 1
  • 8
  • 24

1 Answers1

1

A better late than never answer:

JFXDatePickerContent is the class which is responsible for formatting all cells, days, and months in JFXDatePicker. There is an instance of JFXDatePickerContent inside JFXDatePickerSkin:

JFXDatePicker > JFXDatePickerSkin > JFXDatePickerContent

JFXDatePickerContent provides this method:

protected Locale getLocale() {
    return Locale.getDefault();
}

Although the method looks to be designed to be overridden to return a specific Locale, the class has a package-private constructor. And here is the method that returns that content object from JFXDatePickerSkin:

@Override
protected Node getPopupContent() {
    if (content == null) {
        content = new JFXDatePickerContent(jfxDatePicker);
    }
    return content;
}

The problem is that the private JFXDatePickerContent content object is accessed directly (not using this getter method) inside JFXDatePickerSkin and that means overriding this method to return another custom JFXDatePickerContent (if it were possible) will not make everything work as expected.

Short Answer: Use Locale.setDefault(Locale newLocale); (if that's possible in your application).

I am not sure if the Uzbek language has a support for Cyrillic script but this is how it should be done:

Locale uzCyrl = new Locale.Builder().setLanguage("uz").setScript("Cyrl").build();
Locale.setDefault(uzCyrl);

Here is the output after setting the locale for Spanish / Spain:

Locale.setDefault(new Locale("es", "ES"));

sample output

Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36