JDK-8091503 : [TextArea, TextField] I18N for Default ContextMenu of TextInput
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u20
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-03-27
  • Updated: 2018-09-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Three is no way (that I know of) to change the strings in the default context menu of  TextInputControl (the one with copy/cut/paste/undo/redo/...).

Comments
A workaround is to create a replacement context menu and set it on the TextField/TextArea with the setContextMenu() method. One problem is that if the menu items would call methods directly on the controls, then the skin's undo manager will not be notified. This can be worked around by sending the corresponding key events instead of making those method calls. Attached is an example class called SampleTextInputControlMenu, which does that. Note that it may not work with future versions of FX. Also, it doesn't disable the undo/redo items when there is nothing to undo/redo, but I think that's a minor drawback.
31-03-2014

Yes, I should have thought about that. Now you can go ahead and add items to your menu for all the commands except undo/redo.
28-03-2014

Thank you Leif, but that didn't work. I was able to prevent the default context menu from showing by setting a new empty one on the control: textField.setContextMenu(new ContextMenu()); Got the idea from RT-24823.
28-03-2014

You can prevent the context menu from appearing by using an event filter. textField.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, new EventHandler<ContextMenuEvent>() { @Override public void handle(ContextMenuEvent event) { event.consume(); } });
28-03-2014

No, this is not likely to be fixed soon, so don't depend on it. The only way I can think of for you to get hold of the context menu is to figure out how to extend the Text{Field,Area}Behavior classes and override the contextMenuRequested() methods. This would be specific to a version of FX though, so make sure to add conditionals in your code. See also RT-23213.
28-03-2014

So, this won't be fixed in foreseeable future, right? Any workaround for now? I can accept two solutions: 1) Manually set these strings (but how do I access this context menu's items?) 2) Disable this context menu (how?)
28-03-2014

I'm changing this issue to a Feature, as Java SE has no officially supported mechanism for third parties to provide translations of JRE strings. See also https://bugs.openjdk.java.net/browse/JDK-4703909 As noted, it is possible to provide a jar file with resources on the bootclasspath or in <JRE>/lib/ext, but this has security and integrity issues, and is therefore discouraged.
28-03-2014

It was working for me on the command line with local class files, not using a jar. I believe that if you are running from a jar file, then you'd need to have the resources on the bootclasspath (in a separate jar).
28-03-2014

Thanks Leif. I tried that but the file doesn't seem to be loaded. Same as RT-33417. I even tried Locale.setDefault(Locale) and the command line, but no luck!
28-03-2014

I think this is just a matter of providing some documentation in the right place. The developer or end user can create a translated copy of the file http://hg.openjdk.java.net/openjfx/8/controls/rt/file/tip/modules/controls/src/main/resources/com/sun/javafx/scene/control/skin/resources/controls.properties and place it on the classpath as com/sun/javafx/scene/control/skin/resources/controls_xx.properties, where xx is the locale.
28-03-2014