KeyEventDispatcher receive a consumed event
- From: Jack <jack@xxxxxxxxxx>
- Date: Fri, 27 Jun 2008 16:48:22 +0200
Hi,
in teh flow of my java program, i show a message dialog, which i close with "ESCAPE" key type, but the key also close my JDialog subclass. What is the reason ?
A Simplified version of the code is right below:
// the message
JOptionPane.showMessageDialog(frame, ...);
// i create the dialog
JDialog d = new MyJDialog(frame, true) {
{
super(frame, true);
keyEventDispatcher = new KeyEventDispatcher() {
private boolean done = false;
public boolean dispatchKeyEvent(KeyEvent e) {
if (!done && e.getKeyCode() == KeyEvent.VK_ESCAPE
&& e.getComponent() != null
&& SwingUtilities.windowForComponent(e.getComponent()) == MyJDialog.this
&& !SwingUtilities.isDescendingFrom(e.getComponent(), tableProj)
&& e.getComponent() != textEditor
&& e.getComponent() != combo) {
e.consume();
dispose();
done = true;
}
return false;
}
};
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyEventDispatcher);
}
}
// i show the dialog, but it is closed
d.show();
.
- Prev by Date: (newbie) How to get the UI to update right away
- Next by Date: Re: Weird window close behavior
- Previous by thread: (newbie) How to get the UI to update right away
- Next by thread: teste
- Index(es):