How to add KeyListener to JDialog

۱۲ ۱۰ ۱۳۸۶

You can add KeyListener to your JDialog component as you can add it to any other swing components but when you add other components to JDialog, they eat key events.
To solve this problem you should register KeyboardAction for JDialog. In below code snippet typically I want sense F1 key pressing to do something:

ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
};
KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
JRootPane rootPane = getRootPane();
rootPane.registerKeyboardAction(actionListener, keyStroke,JComponent.WHEN_IN_FOCUSED_WINDOW);

Related Posts


Actions

مشخصه ها

بدون نظر بدون نظر “How to add KeyListener to JDialog”

۱۳ ۱۲ ۱۳۸۶
muhammadNo Gravatar (۰۰:۲۹:۱۳) :

با سلام
کتاب
Java how to program
دارای ادیشن هفتم نیز می باشد
من خیلی دنبال جایی برای دانلود اون گشتم
ولی چیزی پیدا نکردم
ممنون میشم اگه اون رو تو سایتتون قرار بدین

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>