Java Swing KeyStroke synchronizeKeyboardActions( JComponent sourceComponent, JComponent targetComponent, KeyStroke[] keyStrokes, int condition)

Here you can find the source of synchronizeKeyboardActions( JComponent sourceComponent, JComponent targetComponent, KeyStroke[] keyStrokes, int condition)

Description

Registers all actions registered on the source component and registered them on the target component at the specified condition.

License

Open Source License

Parameter

Parameter Description
sourceComponent the source component.
targetComponent the target component.
keyStrokes the keystrokes
condition the condition which will be used in javax.swing.JComponent#registerKeyboardAction(java.awt.event.ActionListener,javax.swing.KeyStroke,int) as the last parameter.

Declaration

public static void synchronizeKeyboardActions(
        JComponent sourceComponent, JComponent targetComponent,
        KeyStroke[] keyStrokes, int condition) 

Method Source Code

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

import java.awt.event.*;

public class Main {
    /**/*ww w .j  a va  2 s  .c  om*/
     * Registers all actions registered on the source component and registered them on the target component at the
     * specified condition.
     *
     * @param sourceComponent the source component.
     * @param targetComponent the target component.
     * @param keyStrokes      the keystrokes
     * @param condition       the condition which will be used in {@link javax.swing.JComponent#registerKeyboardAction(java.awt.event.ActionListener,
     *                        javax.swing.KeyStroke, int)} as the last parameter.
     */
    public static void synchronizeKeyboardActions(
            JComponent sourceComponent, JComponent targetComponent,
            KeyStroke[] keyStrokes, int condition) {
        for (KeyStroke keyStroke : keyStrokes) {
            ActionListener actionListener = sourceComponent
                    .getActionForKeyStroke(keyStroke);
            if (actionListener != null) {
                targetComponent.registerKeyboardAction(actionListener,
                        keyStroke, condition);
            }
        }
    }
}

Related

  1. setKeyBinding(String actionKey, int key, int modifiers, AbstractAction action, JComponent component)
  2. setKeyStroke(JComponent component, KeyStroke keyStroke, Action action)
  3. setUpCycle(JComponent comp, int key)
  4. stringToKeyStroke(String s)
  5. strokeToPrefs(KeyStroke prefsStroke)
  6. synchronizeKeyboardActions( JComponent sourceComponent, JComponent targetComponent, KeyStroke[] keyStrokes, int condition)
  7. unregisterKeyBoardAction(JComponent comp, Action action)
  8. withKeyStroke(M jmi, KeyStroke ks)