Java Swing Key Action addIcons(Action action, String[][] iconRoles)

Here you can find the source of addIcons(Action action, String[][] iconRoles)

Description

Add icons to an action.

License

Open Source License

Parameter

Parameter Description
action The action to which the icons are added.
iconRoles A matrix of Strings, where each element consists of two Strings, the absolute URL of the icon and the key that represents the role of the icon. The keys are usually static fields from this class, such as #LARGE_ICON , #ROLLOVER_ICON , #ROLLOVER_SELECTED_ICON or #SELECTED_ICON .

Declaration

public static void addIcons(Action action, String[][] iconRoles) 

Method Source Code

//package com.java2s;
/*//from   w w  w.j av  a  2 s . co m
 Copyright (c) 1998-2013 The Regents of the University of California
 All rights reserved.
 Permission is hereby granted, without written agreement and without
 license or royalty fees, to use, copy, modify, and distribute this
 software and its documentation for any purpose, provided that the above
 copyright notice and the following two paragraphs appear in all copies
 of this software.

 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 PROVIDED HEREUNDER IS ON AN  BASIS, AND THE UNIVERSITY OF
 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
 ENHANCEMENTS, OR MODIFICATIONS.

 PT_COPYRIGHT_VERSION_2
 COPYRIGHTENDKEY
 */

import java.net.URL;
import javax.swing.Action;

import javax.swing.ImageIcon;

public class Main {
    /** Add icons to an action.  This method is used to associate
     *  icons with the different states: unselected, rollover,
     *  rollover selected, selected etc.
     *
     *  @param action The action to which the icons are added.
     *  @param iconRoles A matrix of Strings, where each element
     *  consists of two Strings, the absolute URL of the icon
     *  and the key that represents the role of the icon.  The keys
     *  are usually static fields from this class, such as
     *  {@link #LARGE_ICON}, {@link #ROLLOVER_ICON},
     *  {@link #ROLLOVER_SELECTED_ICON} or {@link #SELECTED_ICON}.
     */
    public static void addIcons(Action action, String[][] iconRoles) {
        for (String[] iconRole : iconRoles) {
            URL img = action.getClass().getResource(iconRole[0]);
            if (img != null) {
                ImageIcon icon = new ImageIcon(img);
                action.putValue(iconRole[1], icon);
            }
        }
    }
}

Related

  1. addCloseActionWithEscapeKey(final Window window, JRootPane rootPane)
  2. addCtrlEnterAction(JComponent comp, AbstractAction action)
  3. addEnterKey(JComponent control)
  4. addEscKeyAction(javax.swing.JComponent component, javax.swing.InputMap inputMap, javax.swing.Action action)
  5. addHotKey(int key, JComponent to, String actionName, Action action)
  6. addStrokeToName(Action action)
  7. augmentList(Action[] list1, Action[] list2)
  8. dispatchEvent(final KeyEvent ke, final Component comp)
  9. escapeKeyAction(JComponent component, javax.swing.AbstractAction abstractAction)