How can I internationalize the Yes/No/Cancel buttons in a JOptionPane?

John Zukowski

Depending upon which version of Java you are using, there are different answers.

With 1.3, the labels are in properties files. You can add a property file with the labels for a JFileChooser, JColorChooser, and/or JOptionPane. All of these are set in the files basic.properties, or their localized version. The standard JDK from Sun includes ones for Japanese basic_ja.properties and Chinese basic_zh.properties. You would need to create one named appropriately, and located in a directory javax/swing/plaf/basic/resources in your CLASSPATH.

With 1.2/1.1 (and also working in 1.3), you can just tell the UIManager to use different labels before creating the component. For French, you would do the following (assuming my French is correct):

UIManager.put("OptionPane.yesButtonText", "Oui");
UIManager.put("OptionPane.cancelButtonText", "Annulent");
UIManager.put("OptionPane.noButotnText, "Non");
UIManager.put("OptionPane.okButotnText, "D'accord");