Java JTextComponent Key sendKeyPress(JTextComponent target, int v_key, int modifiers)

Here you can find the source of sendKeyPress(JTextComponent target, int v_key, int modifiers)

Description

Create and send a KeyPress KeyEvent to the component given

License

Apache License

Parameter

Parameter Description
target Editor to get the action
v_key from KeyEvent.V_ constants
modifiers from KeyEvent.*MASK constants

Declaration

public static void sendKeyPress(JTextComponent target, int v_key, int modifiers) 

Method Source Code

//package com.java2s;
/*/*from   w w w.  ja v a2  s.c  om*/
 * Copyright 2008 Ayman Al-Sairafi ayman.alsairafi@gmail.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License 
 *       at http://www.apache.org/licenses/LICENSE-2.0 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.  
 */

import java.awt.event.KeyEvent;

import javax.swing.text.JTextComponent;

public class Main {
    /**
     * Create and send a KeyPress KeyEvent to the component given
     * @param target Editor to get the action
     * @param v_key from KeyEvent.V_ constants
     * @param modifiers from KeyEvent.*MASK constants
     */
    public static void sendKeyPress(JTextComponent target, int v_key, int modifiers) {
        KeyEvent ke = new KeyEvent(target, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, v_key,
                KeyEvent.CHAR_UNDEFINED);
        target.dispatchEvent(ke);
    }
}

Related

  1. addKeyBindings(final JTextComponent comp)