InputMap input = getInputMap(); ActionMap actions = getActionMap();  Container parent = getParent(); while ((parent != null) && (parent instanceof JComponent)) { JComponent jParent = (JComponent) parent; InputMap parentInput = jParent.getInputMap(); ActionMap parentAction = jParent.getActionMap();  KeyStroke[] ikeys = input.keys(); for (int i = 0; i < ikeys.length; i++) { Object o = input.get(ikeys[i]); parentInput.put(ikeys[i], o); }  Object[] akeys = actions.keys(); for (int i = 0; i < akeys.length; i++) { Action a = actions.get(akeys[i]); parentAction.put(akeys[i], a); }  parent = jParent.getParent(); }
  public void addNotify()  {    super.addNotify();    // let parents inherit the keybord mapping    InputMap input = getInputMap();    ActionMap actions = getActionMap();    Container parent = getParent();    while ((parent != null) && (parent instanceof JComponent))      {        JComponent jParent = (JComponent) parent;        InputMap parentInput = jParent.getInputMap();        ActionMap parentAction = jParent.getActionMap();        KeyStroke[] ikeys = input.keys();        for (int i = 0; i < ikeys.length; i++)          {            Object o = input.get(ikeys[i]);            parentInput.put(ikeys[i], o);          }        Object[] akeys = actions.keys();        for (int i = 0; i < akeys.length; i++)          {            Action a = actions.get(akeys[i]);            parentAction.put(akeys[i], a);          }        parent = jParent.getParent();      }    // Notify AncestorListeners.    fireAncestorEvent(this, AncestorEvent.ANCESTOR_ADDED);    // fire property change event for 'ancestor'    firePropertyChange("ancestor", null, parent);  }