Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

KeyListener not working in 1.4

Thread view: 
zn?rt - 10 Mar 2004 16:06 GMT
Hi all

I have all my application dialogs derived from a single customized
JDialog that installs a KeyListener to handle help requests through
the F1 key, like this:

public class BizDialog extends JDialog
{
    /* ... */
   this.addKeyListener(new java.awt.event.KeyAdapter()
   {
     public void keyPressed(KeyEvent e)
     {
        this_keyPressed(e);
     }
   });
    /* ... */
}

This worked fine until I switched from jvm 1.3 to 1.4, when it stopped
working. The keyPressed event is simply not fired anymore.

While switching from 1.3 to 1.4 I also changed all intput fields from
JTextField to JFormattedTextfield, wich uses InputVerifier. Could this
be the cause?

Any ideas of why the keyListener doesn't work anymore, and possible
workaround?

regards
znôrt
hiwa - 11 Mar 2004 01:05 GMT
znôrt <kktuapower@yahoo.es> wrote in message news:<3jeu40d8ghd5js9qr9n1o1duapq4cdjm6o@4ax.com>...
> Hi all
>
[quoted text clipped - 27 lines]
> regards
> znôrt

On what component do you expect key would be pressed? If it is on a
JTextField/JFormattedTextfield, you have to add keylistener onto it,
not onto the JDialog itself.
zn?rt - 16 Mar 2004 10:56 GMT
>znôrt <kktuapower@yahoo.es> wrote in message news:<3jeu40d8ghd5js9qr9n1o1duapq4cdjm6o@4ax.com>...
>> Hi all
>>
>> I have all my application dialogs derived from a single customized
>> JDialog that installs a KeyListener to handle help requests through
>> the F1 key, like this:
[...]
>> While switching from 1.3 to 1.4 I also changed all intput fields from
>> JTextField to JFormattedTextfield, wich uses InputVerifier. Could this
[quoted text clipped - 6 lines]
>JTextField/JFormattedTextfield, you have to add keylistener onto it,
>not onto the JDialog itself.

Thank you and sorry for my late posting. This happens regardless of
where the focus is when F1 is pressed.

Back in my version using 1.3+JTextField, it also worked regardless of
focus position, even when it was owned by a JTextField.

This issue isn't very much high priority, so I haven't still put hands
on it really. Just wanted to know in the meanwhile if anybody had
experienced anything similar. Thank you again for your comments.

regards
znôrt
zn?rt - 22 Mar 2004 16:02 GMT
Defintely, adding a global KeyListener won't work on 1.4 if you add
something like a JTextField or JButton to the container. I can swear
it did work on 1.3 :-)

Workaround:

Let the base container class implement ActionListener and ...

this.getRootPane().registerKeyboardAction(this,KeyStroke.getKeyStroke(KeyEvent.VK_F1,0),JComponent.WHEN_IN_FOCUSED_WINDOW);

regards
znôrt


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.