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 / General / May 2007

Tip: Looking for answers? Try searching our database.

Why JWindow can not catch the KEY Type event?

Thread view: 
JTL.zheng - 04 May 2007 13:27 GMT
my code is:

JWindow window= new JWindow();
window.addKeyListener(new KeyListener() {
   public void keyTyped(KeyEvent e) {
                System.out.println((int) e.getKeyChar());
    }
});

but it did not print any thing when I type the keyboard
(however, It can catch the mouse click event)

What should I do if I want to catch the KEY type event in JWindow?
Thank you very much.
Andrew Thompson - 04 May 2007 17:03 GMT
..
>JWindow window= new JWindow();

Somebody asked recently, what good
was a JWiindow, over an undecorated JFrame,
and apparently, *not* for..

>window.addKeyListener(new KeyListener() {

..KeyListener!  I expect it has something to do with
being keyboard focusable - put a text field in it, and
that may change it.

OTOH..

>What should I do if I want to catch the KEY type event in JWindow?

What about something that 'looks just like it'?

<sscce>
import javax.swing.JFrame;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;

public class TestFocus {

 public static void main(String[] args) {

   JFrame f = new JFrame();
   f.setUndecorated(true);
   f.addKeyListener(new KeyListener() {
     public void keyTyped(KeyEvent e) {
       System.out.println((int) e.getKeyChar());
     }
     public void keyReleased(KeyEvent e) {}
     public void keyPressed(KeyEvent e) {}
   });
   System.out.println( "f.isFocusable() " + f.isFocusable() );
   f.setSize(200,200);
   f.setVisible(true);
 }
}
</sscce>

HTH

Signature

Andrew Thompson
http://www.athompson.info/andrew/

JTL.zheng - 05 May 2007 06:32 GMT
haha, Thank you very much, Andrew T
your "something that 'looks just like it'" is exactly what I want!
: )
Andrew Thompson - 05 May 2007 06:42 GMT
..
>your "something that 'looks just like it'" is exactly what I want!
>: )

You're welcome.  Glad to hear it is sorted.   :-)

Signature

Andrew Thompson
http://www.athompson.info/andrew/



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.