List of usage examples for javax.swing JTextField getAction
public Action getAction()
Action
for this ActionEvent
source, or null
if no Action
is set. From source file:Main.java
/** * Programmatically perform action on textfield.This does the same * thing as if the user had pressed enter key in textfield. * * @param textField textField on which action to be preformed *///from w ww. j a v a 2 s . c o m public static void doAction(JTextField textField) { String command = null; if (textField.getAction() != null) command = (String) textField.getAction().getValue(Action.ACTION_COMMAND_KEY); ActionEvent event = null; for (ActionListener listener : textField.getActionListeners()) { if (event == null) event = new ActionEvent(textField, ActionEvent.ACTION_PERFORMED, command, System.currentTimeMillis(), 0); listener.actionPerformed(event); } }