Capturing a KeyEvent with a JWindow

I'm having trouble getting a JWindow to capture a KeyEvent.  I looked in the PAQ's and found this example:

import java.awt.event.*;
import javax.swing.*;

public class JWindowEvents extends JWindow {

 public JWindowEvents() {
   addKeyListener(new KeyAdapter() {
     public void keyPressed(KeyEvent ke) {System.out.println("KeyPressed");}
     public void keyReleased(KeyEvent ke) {System.out.println("KeyReleased");}
     public void keyTyped(KeyEvent ke) { System.out.println("KeyTyped"); }
   });
 }
 public static void main(String[] args) {

   JWindowEvents jwe = new JWindowEvents(frame);
   jwe.setSize(200, 200);
   jwe.setLocation(200, 100);
   jwe.setVisible(true);

   jwe.requestFocus();
 }
}

... I added the 'jwe.requestFocus()' but it still doesn't manage to capture the KeyEvents.  I'm using the 1.4 SDK so I'm not sure if I should be going about it a different way now or not.

Any help would be great.
moshecristelAsked:
Who is Participating?
 
objectsCommented:
I don't think a JWindow can actually recieve the focus so what you are trying to do will not work (as you have already discovered).
0
 
moshecristelAuthor Commented:
objects:

Bummer :(  It's good to know, though.  Thanks for the help.
0
 
objectsCommented:
Happy I could help :-)

http://www.objects.com.au/staff/mick
Brainbench MVP for Java 1
http://www.brainbench.com
0
All Courses

From novice to tech pro — start learning today.