Note that there are some explanatory texts on larger screens.

plurals
  1. POSet locale properly to a JFileChooser
    primarykey
    data
    text
    <p>I'm having a little problem when I change Locale at runtime. </p> <p><strong>The Goal</strong></p> <p>I have to change the Locale of my application language according to a configuration file. </p> <p>This locale does not necessarily be the same of the host/OS locale nor the JVM default locale. </p> <p>Moreover, I can't modify <code>user.language</code> when I call the application. Then, I must do that at runtime.</p> <p><strong>The Problem</strong></p> <p>Summarizing my code, I read the configuration file and get the different options (including locale). After that, I initialize the application environment according to these configured options.</p> <p>After, I build my frame and starts the application life-cycle.</p> <pre class="lang-java prettyprint-override"><code>public static void main(String[] args) { File fichier; Ini ini; //Ini4J object Modele modele = new Modele(); //My Model class: it stores configuration and other stuff try { fichier = new File(Modele.CONFIGURATION); ini = new Ini(fichier); modele.setLocaleLang(ini.get(Modele.LOCALE, Modele.LANG, String.class)); // read more options } catch(InvalidFileFormatException e) { // exception processing } catch (IOException e) { // exception processing } finally { ini = null; fichier = null; } // More code JComponent.setDefaultLocale(modele.getLocaleLang()); // More initialization code MyFrame fenetre = new MyFrame(modele); fenetre.visualiser(); } </code></pre> <p>Well, during the life-cycle, you can open files. Obviously, I use a JFileChooser for that issue:</p> <pre class="lang-java prettyprint-override"><code>JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setFileFilter(modele.FILTRE_OUVRIR); jfc.showOpenDialog(null); </code></pre> <p>All the file chooser it's setted with the configured locale, but the type selector doesn't change. The following image shows the problem (OS Locale: es_ES, configured locale: fr_FR):</p> <p><img src="https://i.stack.imgur.com/A6i14.png" alt="enter image description here"></p> <p>As you can see, in the combobox "Fichiers de type": the option is showed in Spanish instead of French.</p> <p>Colud someone explain me the problem? Is something wrong in my code? Could be a problem due to I'm using a file filter?</p> <p>I thank you for any suggestion.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload