Java Swing Key Action registerTabKey(Container container)

Here you can find the source of registerTabKey(Container container)

Description

Register the tab key with the container.

License

Open Source License

Parameter

Parameter Description
container a parameter

Declaration

public static void registerTabKey(Container container) 

Method Source Code

//package com.java2s;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class Main {
    /**/*from   w w  w  .j a  v  a2  s .  c  o  m*/
     * Register the tab key with the container.
     *
     * @param container
     */
    public static void registerTabKey(Container container) {
        if (container instanceof JComponent) {
            ((JComponent) container).registerKeyboardAction(
                    new AbstractAction() {
                        public void actionPerformed(ActionEvent e) {
                            // JDK 1.3 Porting Hint
                            // comment out for now
                            DefaultKeyboardFocusManager
                                    .getCurrentKeyboardFocusManager()
                                    .focusNextComponent();
                        }
                    }, KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
                    JComponent.WHEN_FOCUSED);
        } else {
            for (int i = 0; i < container.getComponentCount(); i++) {
                Component c = container.getComponent(i);
                // JDK 1.3 Porting Hint
                // change to isFocusTraversable()
                if (c instanceof JComponent && c.isFocusable()) {
                    ((JComponent) container).registerKeyboardAction(
                            new AbstractAction() {
                                public void actionPerformed(ActionEvent e) {
                                    // JDK 1.3 Porting Hint
                                    // comment out for now
                                    DefaultKeyboardFocusManager
                                            .getCurrentKeyboardFocusManager()
                                            .focusNextComponent();
                                }
                            }, KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
                            JComponent.WHEN_FOCUSED);
                }
            }
        }
    }
}

Related

  1. parseKeyStroke(String keyStroke)
  2. parseKeyStroke(String keyStroke)
  3. pressKey(Component component, int keyCode, int modifier)
  4. registerKey(JComponent component, final int keyEvent, int modifiers, Action action)
  5. registerKeyAction(JComponent component, int keyCode, Action action)
  6. registerWindowCloseKeys(JRootPane root, Action closeAction)
  7. removeTabbedPaneFocusTraversalKeyBindings( JComponent c)
  8. replaceAction(InputMap map, char c)
  9. sendKeys(JComponent component, int modifiers, int key)