Is there a way to add a keylistener to JOptionPane.showMessageDialog?
JOptionPane.showMessageDialog(null,"press any key", "title", JOptionPane.INFORMATION_MESSAGE);
If I press enter or space I close the dialog, but i would close the dialog with any key.
Press enter--> close dialog
Press "a" -->close dialog
Press "3" -->close dialog
etcetc
I tried to extend JOptionPane
private class MyPane extends JOptionPane implements KeyListener
{
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, "OKKK");
}
@Override
public void keyReleased(KeyEvent e) {
JOptionPane.showMessageDialog(null, "OKKK");
}
@Override
public void keyTyped(KeyEvent e) {
JOptionPane.showMessageDialog(null, "OKKK");
}
}
but no result
What is the error?