Java Swing Key Event insertKeyListener(Component component, KeyListener l, int index)

Here you can find the source of insertKeyListener(Component component, KeyListener l, int index)

Description

Inserts the key listener at the particular index in the listeners' chain.

License

Open Source License

Parameter

Parameter Description
component a parameter
l a parameter
index a parameter

Declaration

public static void insertKeyListener(Component component,
        KeyListener l, int index) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/* ww w . ja va 2  s .c  om*/
     * Inserts the key listener at the particular index in the listeners' chain.
     *
     * @param component
     * @param l
     * @param index
     */
    public static void insertKeyListener(Component component,
            KeyListener l, int index) {
        KeyListener[] listeners = component.getKeyListeners();
        for (KeyListener listener : listeners) {
            component.removeKeyListener(listener);
        }
        for (int i = 0; i < listeners.length; i++) {
            KeyListener listener = listeners[i];
            if (index == i) {
                component.addKeyListener(l);
            }
            component.addKeyListener(listener);
        }
        // index is too large, add to the end.
        if (index > listeners.length - 1) {
            component.addKeyListener(l);
        }
    }
}

Related

  1. checkRowDownEvent(KeyEvent evt)
  2. esFecha(KeyEvent e)
  3. keyEventGetKeyText(int keycode)
  4. keyEventModifiersToKeyStrokeModifiers(int modifiers)
  5. keyStrokeModMac(String keyStrokeStr)
  6. press(int key)