this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);     this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
详细可参考:Swing_快捷键JTextField

解决方案 »

  1.   

    //经过测试果然,可以,膜拜大神,感谢!代码如下
    package com.test.swing;import java.awt.Dimension;
    import java.awt.KeyboardFocusManager;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.util.Collections;import javax.swing.JFrame;public class Test extends JFrame { public Test(){
    super();
    //this.setPreferredSize(new Dimension(300,200)); this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET); this.setSize(new Dimension(300,200));

    this.addKeyListener(new KeyListener() {

    @Override
    public void keyTyped(KeyEvent e) {
    //System.out.println(e);
    }

    @Override
    public void keyReleased(KeyEvent e) {
    //System.out.println(e);

    }

    @Override
    public void keyPressed(KeyEvent e) {
    System.out.println(e);

    }
    });
    this.setAlwaysOnTop(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);

    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    new Test();
    }}