Hello,

I build my java desktop application using NetBeans 6.7, visually. So I click on the Frame -> Events -> KeyTyped and I add a new handler.
The problem is the key events are not detected! My components are Swing components. Why is this happening?? :(

private void formKeyTyped(java.awt.event.KeyEvent evt) {

        System.out.println("key typed "+evt.getKeyCode());
    }

Please somebody help!

Please somebody help... this is unusual... why does the form not detect the keyboard?

Indeed it's about focus and about the component... I finally got it, thanks for answering. I add a windows listenter + requested focus to the RIGHT component. For example this is not working:

this.requestFocus();
        this.addKeyListener(
             new KeyAdapter() {
            @Override
             public void keyTyped(KeyEvent e){
                 System.out.println("key "+e.getKeyChar()); }
           } 
      );

but this is working:

this.getContentPane().requestFocus();
        this.getContentPane().addKeyListener(
             new KeyAdapter() {
            @Override
             public void keyTyped(KeyEvent e){
                 System.out.println("key "+e.getKeyChar()); }
           } 
      );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.