Here you can find the source of simulateEnterKey(Component c)
Example came from http://tech.chitgoks.com/2010/08/31/simulate-enter-key-on -any-component-using-java/
Parameter | Description |
---|---|
c | a parameter |
public static void simulateEnterKey(Component c)
//package com.java2s; import java.awt.Component; import java.awt.event.KeyEvent; import javax.swing.SwingUtilities; public class Main { /**/* w ww . j av a2 s. co m*/ * Example came from * http://tech.chitgoks.com/2010/08/31/simulate-enter-key-on * -any-component-using-java/ * * @param c */ public static void simulateEnterKey(Component c) { try { KeyEvent ke = new KeyEvent(c, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), -1, KeyEvent.VK_ENTER, (char) KeyEvent.VK_ENTER); 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); } } }