Solved

Capturing a KeyEvent with a JWindow

Posted on 2002-07-21
4
294 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:moshecristel
  • 3
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7168436
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
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 7168438
0
 

Author Comment

by:moshecristel
ID: 7168542
objects:

Bummer :(  It's good to know, though.  Thanks for the help.
0
 
LVL 92

Expert Comment

by:objects
ID: 7170556
Happy I could help :-)

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java jdbc batch example 8 41
maven module vs maven project 3 47
Glassfish admin console not working 1 36
Tagging and Merging on Branch 1 30
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question