I've searched the archives but I haven't found anything particular
dealing with this issue.
I want to set mnemonics for the buttons representing custom supplied
options when creating a JOptionPane, like:
String options = { "Abort", "Continue" };
JOptionPane.showOptionDialog(parentComponent,
message, title, JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING, null, options, options[0]);
I've though of supplying JButton option instances for the options
but then I'm loosing the default button action handling and the
default button look&feel is different from the one seen in a default
JOptionPane.
Is there more convenient way than supplying custom buttons as
options to achieve setting mnemonics on the rendered default buttons?

Signature
Stanimir
Stanimir Stamenkov - 22 Mar 2005 13:41 GMT
/Stanimir Stamenkov/:
> I want to set mnemonics for the buttons representing custom supplied
> options when creating a JOptionPane, like:
[quoted text clipped - 3 lines]
> message, title, JOptionPane.YES_NO_OPTION,
> JOptionPane.WARNING, null, options, options[0]);
O.k. I've just found interesting article:
"Add Mnemonics to Inaccessible Buttons Within a Component"
<http://www.devx.com/tips/Tip/13718>
Other suggestions/pointers are welcome. :-)

Signature
Stanimir
Stanimir Stamenkov - 22 Mar 2005 14:08 GMT
/Stanimir Stamenkov/:
> O.k. I've just found interesting article:
>
> "Add Mnemonics to Inaccessible Buttons Within a Component"
> <http://www.devx.com/tips/Tip/13718>
I've made somewhat tidier variant:
/**
* @param mnemonics Mappings between button labels and the
* corresponding key codes representing the mnemonics.
*/
static void addMnemonicsToButtons(Container parentComponent,
Map mnemonics)
{
Component[] components = parentComponent.getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i] instanceof AbstractButton) {
AbstractButton button =
(AbstractButton) components[i];
String label = button.getText();
if (mnemonics.containsKey(label)) {
int m = ((Integer) mnemonics.get(label))
.intValue();
button.setMnemonic(m);
}
} else if (components[i] instanceof Container) {
addMnemonicsToButtons((Container) components[i],
mnemonics);
}
}
}

Signature
Stanimir