The Artima Developer Community
Sponsored Link

Java Answers Forum
Make a JPanel catch keypresses

1 reply on 1 page. Most recent reply: Sep 23, 2003 10:10 PM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
FVB

Posts: 1
Nickname: pol
Registered: Sep, 2003

Make a JPanel catch keypresses Posted: Sep 23, 2003 1:56 PM
Reply to this message Reply
Advertisement
How can I make a JPanel catch keypresses?

More specific;
I have made a class, extending a JPanel an displayed by the static method JOptionPane.showConfirmDialog(...) .
I want my panel to catch a keypress like F1 to display help.

I tried to implement KeyListener => no reaction.
I tried to add an action to the ActionMap of my panel and wrapped it to a KeyStroke in the Inputmap (something like: myPanel.getInputMap().put(aKeyStroke, aCommand); myPanel.getActionMap().put(aCommand, anAction);) => no reaction.

If I do the same with a textbox, everything goes fine, but it fails on something like a JSpinner or a JPanel.

Some suggestions?


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Make a JPanel catch keypresses Posted: Sep 23, 2003 10:10 PM
Reply to this message Reply
frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke .getKeyStroke(KeyEvent.VK_ALT, Event.F1, false),command);

Flat View: This topic has 1 reply on 1 page
Topic: !!Error using struts [INFO] PropertyMessageResources - -Initializing Previous Topic   Next Topic Topic: Help needed with inheritance!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use