title: How to change language at runtime in java swing
body: <p>I try to change the Locale at runtime in my swing application.<br>
  But I can't figure out how it supposed to work, or there are no master plan?</p>
  
  <p>I can only think of two choices:<br>
  1. Restart the application, not the best user experience.<br>
  2. Create a localization manager that can register/unregister components, on a change it just iterate all components and change the text.<br></p>
  
  <p>Both 1 and 2 feels awkward.</p>
  
  <p>Other info:<br>
  For the moment the orientation is not a target.<br>
  The application is obfuscated.</p>
  
  <p>Example:</p>
  
  <p>LocRes_en.properties:<br></p>
  
  <pre>
  
      text1 = English text
  
  </pre>
  
  <p>LocRes_ja.properties<br></p>
  
  <pre>
  
      text1 = Japanese text
  
  </pre>
  
  <p>ChangeLocale.java:<br></p>
  
  <pre>
  
      import java.awt.EventQueue;
      import java.awt.FlowLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.util.Locale;
      import java.util.ResourceBundle;
  
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
  
      public class ChangeLocale {
  
          private JFrame frame;
  
          public static void main(String[] args) {
              EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      try {
                          ChangeLocale window = new ChangeLocale();
                          window.frame.setVisible(true);
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
              });
          }
  
          public ChangeLocale() {
              initialize();
          }
  
          private void initialize() {
              frame = new JFrame();
              frame.setBounds(100, 100, 450, 300);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 5, 5);
              frame.getContentPane().setLayout(flowLayout);
  
              JButton btnChangeLoc = new JButton("Change Locale");
              frame.getContentPane().add(btnChangeLoc);
  
              final JLabel lblLabel1 = new JLabel("New label");
              frame.getContentPane().add(lblLabel1);
              Locale.setDefault(new Locale("en"));
              ResourceBundle r = ResourceBundle.getBundle("LocRes");
              lblLabel1.setText(r.getString("text1"));
  
              btnChangeLoc.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      Locale.setDefault(new Locale("ja"));
                      ResourceBundle r = ResourceBundle.getBundle("LocRes");
                      // Manually iterate through all components :(
                      lblLabel1.setText(r.getString("text1"));
                      //
                  }
              });
          }
      }<br>
  
  </pre>