3

I have looked and could not find a library that would deal with problem of licalizating the swing component data.

Thus, I decided to create my own and make it public...

Only problem is that I don't really know where the language strings are contained...

If anyone would be so nice to tell me where to look in src folder, I'd be more than happy to create a library that would work something like this:

libraryClassName.JFileChooser.setJFileChooserStringValue(string);

Swing is mentioned in com/sun/java folder, and it's in javax folder too. There are many classes that include the names of swing components per component (JFileChooser.java, FileChooserUI.java, BasicFileChooserUI.java, MetalFileChooserUI.java, MultiFileChooserUI.java, FileChooserPainter.java, etc) and many more general classes that may or may not contain string vaules needed for localization.

I guess, when string values for one component are found, all the others should be in corresponding location.

So, if you help me with this, I'll make a library that will ease the sufferings of so many programmers that are trying to translate their programs...

IMPORTANT EDIT: Is the JFileChooser the only swing component that has predefined strings in it?

Karlovsky120
  • 6,212
  • 8
  • 41
  • 94

1 Answers1

1

OK, I will try not to be lazy and help you with this one:

The file /src/javax/swing/plaf/basic/BasicFileChooserUI.java has nice method called installStrings (line 282), which contains what you are after:

protected void installStrings(JFileChooser fc) {

        Locale l = fc.getLocale();
        newFolderErrorText = UIManager.getString("FileChooser.newFolderErrorText",l);
        newFolderErrorSeparator = UIManager.getString("FileChooser.newFolderErrorSeparator",l);

        newFolderParentDoesntExistTitleText = UIManager.getString("FileChooser.newFolderParentDoesntExistTitleText", l);
        newFolderParentDoesntExistText = UIManager.getString("FileChooser.newFolderParentDoesntExistText", l);
// ...
}

It seems that what you actually need to find is a call to UIManager.getString(String, Locale), which seems to contain the key you are looking for. The actual method definition might reveal even more secrets, but I am too lazy to check it out ;)

Paweł Dyda
  • 18,366
  • 7
  • 57
  • 79
  • Well, I guess that are all of the strings inside a JFileChooser, default values and more I can get by experiemnting... I guess this is all to it... – Karlovsky120 Nov 03 '12 at 17:52
  • Following the method, you get to a dead-end, I think... But I am very interested to find the variable that holds the value of the actuall string... – Karlovsky120 Nov 03 '12 at 17:58
  • Yes, it is a bit tricky. I also recall, that you have to set the translations before constructing the JFileChooser, which was the primary reason I decided to subclass it. Unfortunately, the whole Swing API is rather ugly (and I am speaking from experience). It will give you a headache... – Paweł Dyda Nov 03 '12 at 18:19
  • So, once a JFileChooser is constructed, in order to change the language, you would have to dispose it and construct a new one? – Karlovsky120 Nov 03 '12 at 18:24
  • It seems so. But it is not a problem with desktop applications. You actually should use system language via `Locale.getDefault(Locale.Category.DISPLAY)`. Sometimes, somebody might change system language on the fly, but it will be a corner case. – Paweł Dyda Nov 03 '12 at 19:33