Example usage for javax.swing AbstractButton setActionCommand

List of usage examples for javax.swing AbstractButton setActionCommand

Introduction

In this page you can find the example usage for javax.swing AbstractButton setActionCommand.

Prototype

public void setActionCommand(String actionCommand) 

Source Link

Document

Sets the action command for this button.

Usage

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");

    jb.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
            System.out.println("ChangeEvent!");
        }//from   w  w  w  .j  a va 2  s  .  co  m
    });
    jb.setActionCommand("Bob");

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);
    f.pack();
    f.setVisible(true);
}

From source file:com.projity.menu.ExtToolBarFactory.java

public AbstractButton createJButton(String name)
        throws MissingResourceException, ResourceFormatException, MissingListenerException {
    AbstractButton button = super.createJButton(name);
    try {//from   w  ww .  j av  a2 s .  c o  m
        String s = getString(name + ExtMenuFactory.ICON_SUFFIX);
        ImageIcon icon = IconManager.getIcon(s);
        if (icon != null)
            button.setIcon(icon);
    } catch (MissingResourceException e) {
    }
    String actionName = getActionStringFromId(name);
    if (actionName != null)
        toolButtons.put(actionName, button);
    button.setActionCommand(name);
    return button;
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

protected void prepareButton(AbstractButton button, String actionKey, String iconResource, String toolTipText) {
    button.setActionCommand(actionKey);
    button.setToolTipText(toolTipText);//w  w w.  j ava  2  s .c om
    button.addActionListener(this);
    try {
        button.setIcon(ImageFactory.getIcon(iconResource));
    } catch (ImageFactoryException i) {
        MsgBox.error(i.getMessage());
    }
}

From source file:apidemo.PanScrollZoomDemo.java

/**
 * Prepares a button.//from   w  ww.  java2 s .  co  m
 * 
 * @param button  the button.
 * @param actionKey  the action key.
 * @param buttonLabelText  the button label.
 * @param toolTipText  the tooltip text.
 */
private void prepareButton(final AbstractButton button, final String actionKey, final String buttonLabelText,
        final String toolTipText) {
    // todo
    // as this action is empty and the button text is
    // redefined later, it can be safely removed ...
    //        Action action = new AbstractAction(actionKey) {
    //            public void actionPerformed(ActionEvent evt) {
    //                // ignored
    //            }
    //        };
    //        button.addActionListener(action);
    button.setActionCommand(actionKey);
    button.setText(buttonLabelText);
    button.setToolTipText(toolTipText);
    button.addActionListener(this);
}

From source file:org.nuclos.client.ui.collect.Chart.java

public void addToolbarFunction(String actionCommand, AbstractButton button, JMenuItem mi, int pos) {
    if (toolbarButtons.containsKey(actionCommand))
        toolbar.remove(toolbarButtons.get(actionCommand));
    toolbarButtons.put(actionCommand, button);
    button.setActionCommand(actionCommand);
    button.addActionListener(this);
    toolbar.add(button, pos);// ww w . j  a  va 2s  .c o m
    toolbar.validate();

    if (toolbarMenuItems.containsKey(actionCommand))
        toolbarOrder.remove(actionCommand);
    toolbarMenuItems.put(actionCommand, mi);
    mi.setActionCommand(actionCommand);
    mi.addActionListener(this);
    toolbarOrder.add(pos, actionCommand);
}

From source file:org.openmicroscopy.shoola.agents.imviewer.util.player.MoviePlayerControl.java

/** Adds an {@link ActionListener} to an {@link AbstractButton}. 
 * /* ww  w  . j a  va  2s. co m*/
 * @param button    The component to attach the listener to.
 * @param id        The action command ID.
 */
private void attachButtonListener(AbstractButton button, int id) {
    button.addActionListener(this);
    button.setActionCommand("" + id);
}

From source file:org.openscience.jmol.app.Jmol.java

/**
 * Create a button to go inside of the toolbar.  By default this
 * will load an image resource.  The image filename is relative to
 * the classpath (including the '.' directory if its a part of the
 * classpath), and may either be in a JAR file or a separate file.
 *
 * @param key The key in the resource file to serve as the basis
 *  of lookups./* ww w.  j  a  va  2  s .  com*/
 * @return Button
 */
protected AbstractButton createToolbarButton(String key) {

    ImageIcon ii = JmolResourceHandler.getIconX(key + "Image");
    AbstractButton b = new JButton(ii);
    String isToggleString = JmolResourceHandler.getStringX(key + "Toggle");
    if (isToggleString != null) {
        boolean isToggle = Boolean.valueOf(isToggleString).booleanValue();
        if (isToggle) {
            b = new JToggleButton(ii);
            if (key.equals("rotate"))
                buttonRotate = b;
            toolbarButtonGroup.add(b);
            String isSelectedString = JmolResourceHandler.getStringX(key + "ToggleSelected");
            if (isSelectedString != null) {
                boolean isSelected = Boolean.valueOf(isSelectedString).booleanValue();
                b.setSelected(isSelected);
            }
        }
    }
    b.setRequestFocusEnabled(false);
    b.setMargin(new Insets(1, 1, 1, 1));

    Action a = null;
    String actionCommand = null;
    if (key.endsWith("Script")) {
        actionCommand = JmolResourceHandler.getStringX(key);
        a = executeScriptAction;
    } else {
        actionCommand = key;
        a = getAction(key);
    }
    if (a != null) {
        b.setActionCommand(actionCommand);
        b.addActionListener(a);
        a.addPropertyChangeListener(new ActionChangedListener(b));
        b.setEnabled(a.isEnabled());
    } else {
        b.setEnabled(false);
    }

    String tip = guimap.getLabel(key + "Tip");
    if (tip != null) {
        b.setToolTipText(tip);
    }

    return b;
}

From source file:org.photovault.swingui.framework.AbstractController.java

/**
 * Register an action that can be executed by this controller.
 *
 * @param source The source component, this method sets action command and registers the controller as listener.
 * @param actionCommand The action command, used as a key when registering and executing actions.
 * @param action An actual action implementation.
 *//*w w w  .  jav a 2 s. c  om*/
public void registerAction(AbstractButton source, String actionCommand, DefaultAction action) {
    source.setActionCommand(actionCommand);
    source.addActionListener(this);
    this.actions.put(actionCommand, action);
    final String cmd = actionCommand;
    final AbstractController ctrl = this;
    // TODO: Is this really needed???
    action.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("enabled")) {
                fireEvent(new ActionStateChangeEvent(ctrl, cmd, (Boolean) evt.getNewValue()));
            }
        }

    });
}

From source file:pcgen.gui2.dialog.OptionsPathDialog.java

private void addRadioButton(String text, String command, ButtonGroup group, ActionListener listener,
        GridBagConstraints gbc) {
    boolean selected = command.equals(selectedDir);
    if (selected) {
        text += " (default)"; //for i18n this will need to be handled differently
    }//from w ww. j ava2s  .  co  m
    AbstractButton rButton = new JRadioButton(text);
    rButton.setActionCommand(command);
    rButton.setSelected(selected);
    rButton.addActionListener(listener);
    group.add(rButton);
    getContentPane().add(rButton, gbc);
}