public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } };
private void typedOrPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_TAB) { if (e.getModifiers() == KeyEvent.SHIFT_MASK) { e.getComponent().transferFocusBackward(); } else { e.getComponent().transferFocus(); } e.consume(); } }
public void actionPerformed(ActionEvent evt) { ((Component)evt.getSource()).transferFocus(); } };
if (e.getModifiers() == 0) { if (e.getKeyCode() == KeyEvent.VK_DOWN) e.getComponent().transferFocus(); if (e.getKeyCode() == KeyEvent.VK_UP) e.getComponent().transferFocusBackward();
public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } };
static final Action focusNextAction = new AbstractAction("focusNext") { public void actionPerformed(ActionEvent e) { ((Component)e.getSource()).transferFocus();
public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } };
textArea.transferFocusBackward(); } else { textArea.transferFocus();
public void actionPerformed(ActionEvent evt) { ((Component)evt.getSource()).transferFocus(); } };
public void actionPerformed(ActionEvent evt) { ((Component)evt.getSource()).transferFocus(); } };
public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } };
public void actionPerformed(ActionEvent e) { ((Component) e.getSource()).transferFocus(); } };
pageInfo_.transferFocus(); zoomInfo_.transferFocus();
final CardLayout layout = new CardLayout(); final JComponent main = new JPanel(layout ); Action action = new AbstractAction("toggle cards") { @Override public void actionPerformed(ActionEvent e) { layout.next(main); Component visibleChild = main.getComponent(0).isVisible() ? main.getComponent(0) : main.getComponent(1); visibleChild.transferFocus(); } }; main.getActionMap().put("nextCard", action); main.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke("F2"), "nextCard"); JComponent first = new JPanel(); first.add(new JTextField(20)); first.add(new JButton("dummy on first")); JComponent second = new JPanel(); second.add(new JTextField("I'm on the second")); second.add(new JButton("me on second, too")); main.add(first, "one"); main.add(second, "two");
import java.awt.event.*; import javax.swing.*; public class MyJTextField extends JTextField { private static long lastTime = System.currentTimeMillis(); public MyJTextField(int len) { super(len); addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { long diff = evt.getWhen() - lastTime; System.out.println(diff); if (diff > 50) { transferFocus(); } lastTime = evt.getWhen(); } }); } }
public void actionPerformed(ActionEvent e) editorComponent.transferFocus();
if (invoker != null) if (transferFocus) invoker.transferFocus(); // Focus on next component after invoker
public void focusGained(FocusEvent e) dummy.transferFocus();
if (invoker != null) if (transferFocus) invoker.transferFocus(); // Focus on next component after invoker
case KeyEvent.VK_TAB : e.consume() ; transferFocus() ; break ;