Search code examples
javaactionnetbeans6.8

Action and Name


I'm currently on NetBeans lessons on how to create Java programs with GUI. I've noticed in several GUI controls the text field and the combobox, the "Action" and the "Name" properties are always present. What is the purpose of these properties and how can I use them? For example, I'll use a text field here:

JTextField aTextField = new JTextField();
String act = "aksyon";
JTextField.setActionCommand(act);

What is the difference of setActionCommand() from setAction()? I thank you in advance for your help.


Solution

  • ActionCommand is the key used to determine the command String for the ActionEvent that will be created when an Action is going to be notified as the result of residing in a Keymap associated with a JComponent.

    public void setActionCommand(String command)
    

    Sets the command name for the action event fired by this button. By default this action command is set to match the label of the button. read more here