* [room] Java & действие на Enter
@ 2009-09-07 11:01 Rinat Bikov
2009-09-07 13:05 ` Eugene Prokopiev
0 siblings, 1 reply; 2+ messages in thread
From: Rinat Bikov @ 2009-09-07 11:01 UTC (permalink / raw)
To: Культурный
офтопик,
Michael Pozhidaev
Здравствуйте, уважаемые!
Может кто подсказать, как правильно в Java определить действие на
клавишу Enter во всём фрейме?
Пробовал так:
public class MyFrame extends JFrame{
static {//Этот кусок кода нагуглил, однако не помогло...
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
Keymap map =
JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
map.removeKeyStrokeBinding(enter);
}
...
MyFrame(...){
...
IListener il = new IListener(this);
addKeyListener(il);
}
}
Где в IListener
действие на нажатие клавиши определяется, как
public void keyTyped(KeyEvent e){
if (e.getKeyCode() == KeyEvent.VK_ENTER){
В форме есть 2 текстовых метки, 4 кнопки и 2 текстовых поля ввода.
При появлении окна фокус передаётся на первое текстовое поле.
А вообще, хотелось бы, чтобы при нажатии кнопки Enter выполнялось действие,
назначенное на одну из кнопок...
--
С уважением, Ринат Биков.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-09-07 13:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-07 11:01 [room] Java & действие на Enter Rinat Bikov
2009-09-07 13:05 ` Eugene Prokopiev
Культурный офтопик
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/smoke-room/0 smoke-room/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 smoke-room smoke-room/ http://lore.altlinux.org/smoke-room \
smoke-room@lists.altlinux.org smoke-room@lists.altlinux.ru smoke-room@lists.altlinux.com smoke-room@altlinux.ru smoke-room@altlinux.org smoke-room@altlinux.com
public-inbox-index smoke-room
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.smoke-room
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git