Here you can find the source of simulateKeyStrokes(Component comp, String text)
public static void simulateKeyStrokes(Component comp, String text) throws Exception
//package com.java2s; import java.awt.Component; import java.awt.event.KeyEvent; import javax.swing.SwingUtilities; public class Main { public static void simulateKeyStrokes(Component comp, String text) throws Exception { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); simulateKeyStroke(comp, c);/*from ww w . j a v a 2 s . com*/ } } public static void simulateKeyStroke(Component c, char ch) { try { KeyEvent ke = new KeyEvent(c, KeyEvent.KEY_TYPED, System.currentTimeMillis(), 0, KeyEvent.VK_UNDEFINED, (char) ch); c.requestFocusInWindow(); dispatchEvent(ke, c); } catch (Exception ex) { } } private static void dispatchEvent(final KeyEvent ke, final Component comp) throws Exception { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { comp.dispatchEvent(ke); } }); } else { comp.dispatchEvent(ke); } } }