Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8221660

Enforce locale used to translate displayed menu keyboard shortcuts

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Java 11 (or older), Windows 10 (or older)

      A DESCRIPTION OF THE PROBLEM :
      Let's say I have installed an English Windows OS (which has the entire UI in English). And I want in a started Java application, based on its own internal application settings to force the default locale used for translating shortcut keys to be for example German by using: Locale.setDefault(new Locale("de", "DE"));
      Methods like this "java.awt.event.KeyEvent.getKeyModifiersText(int)" delegate to the "Toolkit.getProperty(String, String)" which uses an internal "java.awt.Toolkit.resources" field which is initialized very early and is impossible to change from the outside except by using Java reflection.

      So I need some kind of new method "Toolkit.setLocale(newLocale)" which could be used to re-initialize the "resources" field set inside it.

      Sample code:

      public static void main(String[] args) {
      Locale.setDefault(new Locale("de", "DE"));
      JMenuItem jmi = new JMenuItem("some text");
      jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.SHIFT_MASK));

      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400, 400);
      frame.getContentPane().add(jmi);
      frame.setVisible(true);
      }

      when you open the top menu the menu item should have the shortcut shown translated in the German language.


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                aaprameya Arvind Aprameya
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: