Skip to main content

Are JOptionPane.YES_NO_OPTION button bar text translatable?

1 reply [Last post]
Anonymous

Hi,
I am new to the Swing technology.
In my application I am displaying a confirm dialog box using the below code

if (JOptionPane.showConfirmDialog(
Jahe.temp.frame,
getMessage(mesgName),
Translation.lookup("CONFIRM"),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
== JOptionPane.NO_OPTION)
return false;
else
return true;

Are the labels of the Yes/No buttons translatable ?
Ono of the customers is complaining that the labels are not shown in his language.
If the JOptionPane doesn't support the translation of label strings, how can I achieve it ?

Thanks in advance,
Anil.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
leouser
Offline
Joined: 2005-12-12

well, from looking at the class hiearchy there appears to be a setLocale in Component. So you can attempt to internationalize, but I believe you would need to know what the keys are for the yes no button. The source code may be your best friend to try and deduce that.

A different option may to just pass in the strings you want.
The options detail gives us these directions:
optionType
Defines the set of option buttons that appear at the bottom of the dialog box:

* DEFAULT_OPTION
* YES_NO_OPTION
* YES_NO_CANCEL_OPTION
* OK_CANCEL_OPTION

You aren't limited to this set of option buttons. You can provide any buttons you want using the options parameter.
options
A more detailed description of the set of option buttons that will appear at the bottom of the dialog box. The usual value for the options parameter is an array of Strings. But the parameter type is an array of Objects. A button is created for each object depending on its type:
----(see javadoc for more)----

my guess is that you may be able to create a ResourceBundle and get your Yes/No option from that. Then you can just pass in the right localized strings through the Options parameter. You probably will need to test against the localized strings to determine what the user selected as well.

leouser