How do you simulate a click on a JTextField? Equivalent of JButton doClick()?
问题 I am working on a Java project and need to have a keypress simulate a click on a JTextField. What I'm looking for is the equivalent of the JButton doClick() method. I am trying to have the keypress "enter" perform the exact same function as a click on the JTextField. Not sure what other info to provide. Thanks in advance. 回答1: public void simulateKey(KeyEvent e, Component c) { Field f = KeyEvent.class.getField("focusManagerIsDispatching"); f.setAccessible(true); f.set(e, Boolean.TRUE); c