Example usage for javax.swing JTextField getAction

List of usage examples for javax.swing JTextField getAction

Introduction

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

Prototype

public Action getAction() 

Source Link

Document

Returns the currently set Action for this ActionEvent source, or null if no Action is set.

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
 *///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);
    }
}