2014-09-05 82 views
1

所以我有2个组件在我的框架,表和文本字段。但是当 表具有焦点并且我点击了tab键时,焦点不会进入文字 字段。为什么发生这种情况?tab键不能转移焦点为JTable

public static void main(String[] args) { 
    SwingUtilities.invokeLater(new Runnable() { 
     public void run() { 
      JFrame frame = new JFrame(); 
      String[][] data = { { "Data" } }; 
      String[] cols = { "COlo" }; 
      JTable table = new JTable(data, cols); 
      table.addFocusListener(new FocusListener() { 

       public void focusLost(FocusEvent arg0) { 
        System.out.println("focus lost"); 
       } 

       public void focusGained(FocusEvent arg0) { 
        System.out.println("gained"); 
       } 
      }); 
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      frame.add(table, BorderLayout.NORTH); 
      frame.add(new JTextField(), BorderLayout.SOUTH); 
      frame.setVisible(true); 
      table.requestFocus(); 

     } 
    }); 
} 
+1

这是一篇旧文章,但它可能为您所看到的内容提供解释。 https://www.java.net/node/651087。另外,请尝试在StackOverflow中搜索“JTable focustraversalpolicy” – terrywb 2014-09-05 23:12:00

回答