Java JMenu isAtLeastOneChildComponentVisible(JMenu menu)

Here you can find the source of isAtLeastOneChildComponentVisible(JMenu menu)

Description

Convenience method that calls the method isAtLeastOneChildComponentVisible(Container) with the JPopupMenu of the given menu as parameter.

License

Apache License

Parameter

Parameter Description
menu the menu that will be checked

Return

true if at least one child component is visible, false otherwise.

Declaration

public static boolean isAtLeastOneChildComponentVisible(JMenu menu) 

Method Source Code


//package com.java2s;
/*/*from   ww w  . j  a  v a2  s  .  c  o m*/
 * Zed Attack Proxy (ZAP) and its related class files.
 * 
 * ZAP is an HTTP/HTTPS proxy for assessing web application security.
 * 
 * Copyright 2014 The ZAP Development Team
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.Component;
import java.awt.Container;
import javax.swing.JMenu;

public class Main {
    /**
     * Tells whether or not the given {@code component} has at least one child component visible.
     * 
     * @param component the component that will be checked
     * @return {@code true} if at least one child component is visible, {@code false} otherwise.
     */
    public static boolean isAtLeastOneChildComponentVisible(Container component) {
        for (Component comp : component.getComponents()) {
            if (comp.isVisible()) {
                return true;
            }
        }
        return false;
    }

    /**
     * Convenience method that calls the method {@code isAtLeastOneChildComponentVisible(Container)} with the {@code JPopupMenu}
     * of the given {@code menu} as parameter.
     * 
     * @param menu the menu that will be checked
     * @return {@code true} if at least one child component is visible, {@code false} otherwise.
     * @see #isAtLeastOneChildComponentVisible(Container)
     * @see JMenu
     */
    public static boolean isAtLeastOneChildComponentVisible(JMenu menu) {
        return isAtLeastOneChildComponentVisible(menu.getPopupMenu());
    }
}

Related

  1. getMenuItem(JMenu menu, String text)
  2. getMenuItemIndex(JMenu menu, String menuItemText)
  3. getMenuItems(JMenu menu)
  4. getTextByJMenu(List lstMenus)
  5. insertSeparatorIfNeeded(JMenu menu, int position)
  6. limitMenuSize(JMenu menu, String name, int size)
  7. makeMenu(JMenu menu, List menuItems)
  8. menuItem(JMenu parent, String label, Object... attrs)
  9. removeAllSeparators(JMenu menu)