Example usage for javax.swing.text JTextComponent DEFAULT_KEYMAP

List of usage examples for javax.swing.text JTextComponent DEFAULT_KEYMAP

Introduction

In this page you can find the example usage for javax.swing.text JTextComponent DEFAULT_KEYMAP.

Prototype

String DEFAULT_KEYMAP

To view the source code for javax.swing.text JTextComponent DEFAULT_KEYMAP.

Click Source Link

Document

The default keymap that will be shared by all JTextComponent instances unless they have had a different keymap set.

Usage

From source file:Main.java

/**
 * initialize keystroke bindings// w  ww  .j a  v  a  2  s.  c om
 */
public final static void InitializeKeyStrokeBindings() {
    String selectAllAction = DefaultEditorKit.selectAllAction;
    String cutAction = DefaultEditorKit.cutAction;
    String copyAction = DefaultEditorKit.copyAction;
    String pasteAction = DefaultEditorKit.pasteAction;

    int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    JTextComponent.KeyBinding ctrlA = new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_A, mask),
            selectAllAction);
    JTextComponent.KeyBinding ctrlX = new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_X, mask),
            cutAction);
    JTextComponent.KeyBinding ctrlC = new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C, mask),
            copyAction);
    JTextComponent.KeyBinding ctrlV = new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V, mask),
            pasteAction);

    JTextComponent.KeyBinding[] extraBindings = new JTextComponent.KeyBinding[] { ctrlA, ctrlX, ctrlC, ctrlV };

    Keymap defaultKeyMap = JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);

    JTextComponent dummy = new JTextField();
    JTextComponent.loadKeymap(defaultKeyMap, extraBindings, dummy.getActions());
}