Java JTextField doAction(JTextField textField)

Here you can find the source of doAction(JTextField textField)

Description

Programmatically perform action on textfield.This does the same thing as if the user had pressed enter key in textfield.

License

Open Source License

Parameter

Parameter Description
textField textField on which action to be preformed

Declaration

public static void doAction(JTextField textField) 

Method Source Code

//package com.java2s;
/**/*from w  w  w.  j  a  v a  2 s  .  com*/
 * JLibs: Common Utilities for Java
 * Copyright (C) 2009  Santhosh Kumar T <santhosh.tekuri@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

import javax.swing.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Main {
    /**
     * 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
     */
    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);
        }
    }
}

Related

  1. cleanTextFields(JTextField... textFields)
  2. createBrowseButton(final JTextField txtInput, final Window parent, final boolean directoryBrowser)
  3. createFieldWithLabel(String label, JTextField textField)
  4. createOutputPanel(JLabel outputFileNameLabel, JButton chooseOutputFileButton, JTextField outputFileTextField, String borderTitle)
  5. dateCompleteOnlyFormat(JTextField pJTextField, KeyEvent e)
  6. fieldSetErrorVisual(final JTextField field)
  7. implyDisabled(final JCheckBox checked, final boolean checkedState, final JTextField changed)
  8. isActiveComponents(JTextField... textFields)
  9. isEmptyStr(javax.swing.JTextField input)