When adding a DatePicker to my app I get the following:
I assume this is because I use Hebrew on my computer. How can I change the language of the DatePicker to be English?
When adding a DatePicker to my app I get the following:
I assume this is because I use Hebrew on my computer. How can I change the language of the DatePicker to be English?
Starting with fx9, the skins are moved out into public api - so you might consider creating a custom skin that allows to configure the Locale per-picker. Unfortunately, the class that does the internal formatting is still hidden in internals, so tweaking requires to go dirty.
If you are daring/allowed to access internals, one way to go is
getLocale()
to first check whether the picker's properties contain a custom locale - if so return that, otherwise delegate to superSample code:
You can define the default locale for your instance of the Java Virtual Machine calling:
Or if you can't find the locale, you need, in the pre made constants, you can look up the country code in the list of officially supported locales and create your "custom" locale like this:
on the
start
method. If you also want to implement a custom formatter for the text editor, you should add locale to the formatter too.This is just an example:
EDIT
By design,
DatePicker
usesLocale.getDefault()
in all the formats applied to the controls displayed on the popup. This can be checked incom.sun.javafx.scene.control.skin.DatePickerContent
class.Unless you provide a custom skin for the control changing these formatters, in order to change the
DatePicker
content to English, avoiding further changes in other localized controls, a workaround could be this:EDIT 2
Returning to the original locale on
setOnShown
is too soon, since if the user changes the month, the original locale is used and it will not be shown properly. To work it should be turned off both onsetOnHiding
and onsetOnAction
.