Example usage for javax.swing JTextField getActionListeners

List of usage examples for javax.swing JTextField getActionListeners

Introduction

In this page you can find the example usage for javax.swing JTextField getActionListeners.

Prototype

@BeanProperty(bound = false)
public synchronized ActionListener[] getActionListeners() 

Source Link

Document

Returns an array of all the ActionListeners added to this JTextField with addActionListener().

Usage

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
 *///w w w  . j a v a 2  s  .  com
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);
    }
}