I have created an instance of JOptionPane and used createDialog.
However, I still don't see a way to manipulate the hot-keys.
Okay, so it's a bit more complex than all that...I underestimated the
work involved. It is still probably easier than creating your own
dialog, since you'd have to do most of the following anyhow. Here's an
example using a JOptionPane, where the "Yes" button is clicked when the
user presses 'y'.
public static void showConfirm() {
final JButton[] options = {
new JButton("Yes"), new JButton("No"), new JButton("Cancel")
};
options[0].setActionCommand("yes");
options[1].setActionCommand("no");
options[2].setActionCommand("cancel");
final JOptionPane pane = new JOptionPane("Confirm?",
JOptionPane.QUESTION_MESSAGE, 0, null, options);
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
pane.setValue(e.getActionCommand());
}
};
options[0].addActionListener(al);
options[1].addActionListener(al);
options[2].addActionListener(al);
Object key = new Object();
pane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke('y'), key);
pane.getInputMap(JComponent.WHEN_FOCUSED)
.put(KeyStroke.getKeyStroke('y'), key);
pane.getInputMap(
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke('y'), key);
pane.getActionMap().put(key, new AbstractAction() {
public void actionPerformed(ActionEvent e)
{
options[0].doClick();
}
});
pane.createDialog(null, "Huh?").show();
}
There are probably better ways to do this, but this is what I came up
with on-the-fly.
Walter
----
Walter Gildersleeve
Freiburg, Germany
"In science, 'fact' can only mean 'confirmed to such a degree that it
would be perverse to withhold provisional assent.' I suppose that
apples might start to rise tomorrow, but the possibility does not merit
equal time in physics classrooms." -- Stephen Jay Gould
______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.