Hello to all,
I'm trying to localize a JFileChooser in OSX; The problem is that the elements on the JFileChooser doesn't get localized after setting a defaut locale before instantiating any of the Swing components. If you run the following code in OSX () you will see the problem:
import java.awt.EventQueue;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
public class TestJFileChooserLocalization {
/**
* @param args
* @throws InvocationTargetException
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
Locale esL = new Locale("es", "VE");
Locale.setDefault(esL);
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JFileChooser chooser = new JFileChooser();
frame.add(chooser);
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.pack();
frame.setVisible(true);
chooser.showSaveDialog(frame);
}
});
}
}
{code}After checking on this forums and the Internet I found the following information that suggests how to solve the problem by replacing the text properties using the class UIManager:
[http://www.rgagnon.com/javadetails/java-0299.html]
[http://forums.sun.com/thread.jspa?threadID=5344457]
[http://lists.apple.com/archives/Java-dev/2006/Apr/msg00281.html]
At the end, I resorted to put my custom text on a ResourceBundle and setting this properties before any Swing component gets instantiated and that works (just showing up the changes):
[code]
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
Locale esL = new Locale("es", "VE");
Locale.setDefault(esL);
ResourceBundle jfilechooserBndl = ResourceBundle.getBundle("JFileChooser", esL);
Enumeration<String> keyEn = jfilechooserBndl.getKeys();
while (keyEn.hasMoreElements()) {
String key = keyEn.nextElement();
UIManager.put(key, jfilechooserBndl.getString(key));
}
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JFileChooser chooser = new JFileChooser();
frame.add(chooser);
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.pack();
frame.setVisible(true);
chooser.showSaveDialog(frame);
}
});
}
[/code]
And the ResourceBundle:
[code]
FileChooser.fileNameLabelText=Nombre del archivo
FileChooser.homeFolderToolTipText=Directorio hogar
FileChooser.newFolderToolTipText=Nueva carpeta
FileChooser.listViewButtonToolTipTextlist=Ver lista
FileChooser.detailsViewButtonToolTipText=Detalles
FileChooser.newFolderButtonText=Nueva carpeta
FileChooser.saveButtonText=Guardar
FileChooser.openButtonText=Abrir
FileChooser.cancelButtonText=Cancelar
FileChooser.updateButtonText=Actualizar
FileChooser.helpButtonText=Ayuda
FileChooser.saveButtonToolTipText=Guardar
FileChooser.openButtonToolTipText=Abrir
FileChooser.cancelButtonToolTipText=Cancelar
FileChooser.updateButtonToolTipText=Actualizar
FileChooser.helpButtonToolTipText=Ayuda
FileChooser.lookInLabelText=Buscar en
FileChooser.filesOfTypeLabelText=Archivos de tipo
FileChooser.upFolderToolTipText=Ir un nivel arriba
[/code]
Here are my questions:
# Is this the best way to solve this problem? I wonder if this leaves you open to a chance on the name of the properties in the future
# There is a way to get the FULL list of properties tht can be set for a JFileChooser?
Thanks in advance.
Jose.