Is there a way to change language of ColorPicker
's texts such as "Custom Color...", "Current Color", "New Color", "Hue", "Saturation", "Brightness", "Opacity", "Save", "Use", "Cancel"?

- 1,682
- 2
- 21
- 44
-
For translation of standard system window on the other languages is some information here: https://stackoverflow.com/a/45980313/3937190 – Andrei Krasutski Aug 31 '17 at 12:26
2 Answers
EDIT: Below answer is for those who need some more exotic language. If you use one of those: de, es, fr, it, ja, ko, pt, sv, zh
@sergey-grinev provided sufficient answer.
I came up with two solutions. Both rely on properties
file. You can create your own based on examples found in com/sun/javafx/scene/control/skin/resources/
in jxfrt.jar
provided with JRE.
All examples will use polish Locale (new Locale("pl", "PL")
) which is not built-in.
Solution 1
Create JAR file with following structure (change suffix accordingly)
com/sun/javafx/scene/control/skin/resources/controls_pl_PL.properties
and place it in
<path_to_JVM>/lib/ext
That's it.
I'm not sure what the license says about placing custom files in com.sun.*
packages, so here's another solution.
Solution 2
Create properties
file like above, but you can name it whatever and place it wherever you want. Let's say it will be
path/to/my/resources/polish.properties
Create two classes - ResourceBundle.Control
and ResourceBundleControlProvider
(read more) like this.
public class CustomLocaleFxResourceBundleControl extends ResourceBundle.Control {
static final String FX_BASE_NAME = "com/sun/javafx/scene/control/skin/resources/controls";
private static final Locale MY_LOCALE = new Locale("pl", "PL");
@Override
public String toBundleName(String baseName, Locale locale) {
if (FX_BASE_NAME.equals(baseName) && MY_LOCALE.equals(locale))
return "path/to/my/resources/polish"; // without extension
return super.toBundleName(baseName, locale);
}
}
public class CustomLocaleFxResourceBundleControlProvider implements ResourceBundleControlProvider {
private static final ResourceBundle.Control MY_RESOURCE_BUNDLE_CONTROL = new CustomLocaleFxResourceBundleControl();
public ResourceBundle.Control getControl(String baseName) {
if (CustomLocaleFxResourceBundleControl.FX_BASE_NAME.equals(baseName))
return MY_RESOURCE_BUNDLE_CONTROL;
return null;
}
}
Compile those classes and put them in JAR file along with your resource and META-INF
folder. META-INF
folder should have following structure
META-INF/services/java.util.spi.ResourceBundleControlProvider
java.util.spi.ResourceBundleControlProvider
is a text file which only line is path to ResourceBundleControlProvider
class. In our case it's just
CustomLocaleFxResourceBundleControlProvider
Complete JAR put in
<path_to_JVM>/lib/ext
-
This is my first time making such changes and I'm having some troubles. I'm using Eclipse(jdk 1.8.40) and can't find properties file that you mentioned above. – Alyona Apr 14 '15 at 12:55
-
In `
/jre/lib/ext` there is `jfxrt.jar`. Copy it, change extension to `zip`, unpack and look in the directory mentioned in my answer. – 3ph3r Apr 14 '15 at 19:32 -
Thank you, I retrieved needed properties file and made changes to it. I created both CustomLocaleFxResourceBundleControlProvider and CustomLocaleFxResourceBundleControl in bin\com\my folder (where mainApp is), also put there controls_pl.properties file. But I am confused about "Compile those classes and put them in JAR file along with your resource and META-INF folder. META-INF folder should have following structure". I just can't understand what exactly to do. I'm at begginer level with Java and can't yet understand all. – Alyona Apr 15 '15 at 11:44
-
If I'm not mistaken Eclipse is compiling program on the fly. Should I compile those two classes manualy? Can't understand in which jar should I put these classes. In the same jar, from which I took properties file? If I look at Java FX DDK, that I'm using, it has org.eclipse.fx.ide.css.jfx8_1.0.0.jar in which META-INF with only maven folder in it. Should I create META-INF/services/java.util.spi.ResourceBundleControlProvider? – Alyona Apr 15 '15 at 11:52
-
You can manually prepare desired directory structure ([screen](http://i.imgur.com/vzdXGHO.png)). Enter `toJar` folder, select all, right click, add to ZIP archive (depends on your installed software). After that change extension of result `.zip` to `.jar`. You can pick `.class` files from `bin` directory in eclipse project. In your situation move them first to default package - declared package and path within JAR must be the same. – 3ph3r Apr 15 '15 at 21:01
-
Thank you fro screenshot! It helped a lot. Should I put jar file C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext or go to properties for project and add jar to jdk library? – Alyona Apr 17 '15 at 18:12
-
As stated in my answer `
/lib/ext`, so in your situation `C:/Program Files/Java/jdk1.8.0_40/jre/lib/ext`. – 3ph3r Apr 17 '15 at 19:24 -
Added everything and restarted eclipse. After running program I got exception: Could not initialize class java.util.ResourceBundle. [screen](http://s019.radikal.ru/i636/1504/80/0e96499e8a60.jpg) – Alyona Apr 17 '15 at 20:31
-
I've decided for now to use first solution, but later I will definitely figure out what I could possibly do wrong in second one) Thank you for all your explanations. – Alyona Apr 19 '15 at 15:16
The easiest way is to use one of predefined locales, e.g. add next line before creating ColorPicker:
Locale.setDefault(Locale.FRENCH);
You'll see next UI:

- 34,078
- 10
- 128
- 141
-
2It works for French. But what to do, if I need to create ColorPicker for other languages like Russian or Estonian? Tried to use ` Locale dLocale = new Locale("ru"); Locale.setDefault(dLocale);` , but it doesn't work. – Alyona Apr 13 '15 at 21:04
-
@user3629015 lol, Russian and Estonian are two languages I speak besides English :) Take a look at 3ph3r answer in this case. – Sergey Grinev Apr 14 '15 at 00:05
-
-
1@sinedsem Я не забыл, смотрите мой ответ здесь https://stackoverflow.com/a/45979456/3937190 – Andrei Krasutski Aug 31 '17 at 10:55
-
@AndreiKrasutski thanks, but I've already become disappointed about JavaFX and desktop java development – sinedsem Sep 01 '17 at 09:04