So i have 2 components in my frame, a table and a text field. but when the table has the focus and I hit tab key, the focus doesn't go to the text field. Why this is happening?
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();
}
});
}