JavaFX颜色选择器的语言 [英] Language of JavaFX color picker
问题描述
有没有办法改变 ColorPicker
的语言,如自定义颜色......,当前颜色,新颜色,色调 ,饱和度,亮度,不透明度,保存,使用,取消?
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"?
推荐答案
编辑:以下答案适合那些需要更多异国情调语言的人。如果你使用其中一个: de,es,fr,it,ja,ko,pt,sv,zh
@ sergey-grinev提供了足够的答案。
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.
我想出了两个解决方案。两者都依赖于属性
文件。您可以根据 jxfrt.jar $中
com / sun / javafx / scene / control / skin / resources /
中的示例创建自己的示例c $ c>随JRE提供。
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.
所有示例都将使用波兰区域设置(新区域设置(pl,PL)
)不是内置的。
All examples will use polish Locale (new Locale("pl", "PL")
) which is not built-in.
创建具有以下结构的JAR文件(相应地更改后缀)
Create JAR file with following structure (change suffix accordingly)
com/sun/javafx/scene/control/skin/resources/controls_pl_PL.properties
并将其放入
<path_to_JVM>/lib/ext
就是这样。
我不确定许可证中有关将自定义文件放在 com.sun中的内容。*
包,所以这是另一个解决方案。
I'm not sure what the license says about placing custom files in com.sun.*
packages, so here's another solution.
创建属性
文件如上所述,但您可以将其命名为任何位置并将其放置在您想要的任何位置。假设它将是
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
创建两个类 - ResourceBundle.Control
和 ResourceBundleControlProvider
(了解更多)像这样。
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;
}
}
编译这些类并将它们放在JAR文件中您的资源和 META-INF
文件夹。 META-INF
文件夹应具有以下结构
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
是一个文本文件,其中只有行是 ResourceBundleControlProvider
类的路径。在我们的例子中它只是
java.util.spi.ResourceBundleControlProvider
is a text file which only line is path to ResourceBundleControlProvider
class. In our case it's just
CustomLocaleFxResourceBundleControlProvider
完成JAR放入
<path_to_JVM>/lib/ext
这篇关于JavaFX颜色选择器的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!