Java JComponent set focus traversal keys
import java.awt.BorderLayout; import java.awt.KeyboardFocusManager; import java.util.HashSet; import java.util.Set; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.KeyStroke; public class Main { public static void main(String[] argv) throws Exception { JComponent component = new JTextField(); Set set = new HashSet(component.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); set.add(KeyStroke.getKeyStroke("F2")); component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set); /* www.ja va 2s.com*/ JFrame f = new JFrame(); f.add(component, BorderLayout.NORTH); f.add(new JTextField(10), BorderLayout.SOUTH); f.setSize(300, 300); f.setVisible(true); } }