Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Setting JOptionPane button labels to French

To start the Java runtime with a different language, just set the user.language property, as in java -Duser.language=FR ClassName. Then, whenever you create a JOptionPane, you would get the French labels for Yes, No, OK, and Cancel. import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; public class ConfigOptionPaneLanguage {   public static void main(final String[] args) { //       UIManager.put("OptionPane.cancelButtonText", "Annuler");     UIManager.put("OptionPane.noButtonText", "Non");     UIManager.put("OptionPane.okButtonText", "D'accord");     UIManager.put("OptionPane.yesButtonText", "Oui");     JFrame parent = new JFrame();          String multiLineMsg[] = { "Hello,", "World"} ;     JOptionPane.showMessageDialog(parent, multiLineMsg);   } }