Java Swing Menu Item getMenuItem(Container container, Action action)

Here you can find the source of getMenuItem(Container container, Action action)

Description

Recursively search the contents of the container to find a MenuItem or Button that uses this action.

License

Open Source License

Parameter

Parameter Description
container a parameter
action a parameter

Declaration

public static AbstractButton getMenuItem(Container container, Action action) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2012 Firestar Software, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors://from   w w  w .j a  va 2s.c  om
*     Firestar Software, Inc. - initial API and implementation
*
* Author:
*     Sally Conway
*
*******************************************************************************/

import java.awt.Component;
import java.awt.Container;
import javax.swing.AbstractButton;
import javax.swing.Action;

public class Main {
    /** Recursively search the contents of the container to find a MenuItem or Button
     * that uses this action.
     * @param container
     * @param action
     * @return
     */
    public static AbstractButton getMenuItem(Container container, Action action) {
        for (int i = 0; i < container.getComponentCount(); i++) {
            Component item = container.getComponent(i);
            if (item instanceof AbstractButton && ((AbstractButton) item).getAction().equals(action)) {
                return (AbstractButton) item;
            } else if (item instanceof Container) {
                return getMenuItem((Container) item, action);
            }
        }
        return null;
    }
}

Related

  1. createMenuItem(T source, int mnemonic, String description, E action)
  2. createRadioButtonMenuItem(final String text, final boolean selected)
  3. faqMenuItem()
  4. findMenuItem(Container container, String[] path)
  5. getExitMenuItem()
  6. getMenuItem(Container owner, String text)
  7. getMenuItemBorder()
  8. getMenuItemDisabledForegroundObject()
  9. getMenuItemParent()