Here you can find the source of insertKeyListener(Component component, KeyListener l, int index)
Parameter | Description |
---|---|
component | a parameter |
l | a parameter |
index | a parameter |
public static void insertKeyListener(Component component, KeyListener l, int index)
//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); } } }