Here you can find the source of removeTopAndBottomSeparators(JPopupMenu popupMenu)
Parameter | Description |
---|---|
popupMenu | the pop up menu whose top and bottom separators will be removed |
public static void removeTopAndBottomSeparators(JPopupMenu popupMenu)
//package com.java2s; /*/*from w w 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 javax.swing.JMenu; import javax.swing.JPopupMenu; public class Main { /** * Convenience method that calls the methods {@code removeTopSeparators(JPopupMenu)} and * {@code removeBottomSeparators(JPopupMenu)} with the given pop up menu as parameter. * * @param popupMenu the pop up menu whose top and bottom separators will be removed * @see #removeTopSeparators(JPopupMenu) * @see #removeBottomSeparators(JPopupMenu) * @see javax.swing.JPopupMenu.Separator */ public static void removeTopAndBottomSeparators(JPopupMenu popupMenu) { if (popupMenu.getComponentCount() == 0) { return; } removeTopSeparators(popupMenu); removeBottomSeparators(popupMenu); } /** * Convenience method that calls the method {@code removeTopAndBottomSeparators(JPopupMenu)} with the {@code JPopupMenu} of * the given {@code menu} as parameter. * * @param menu the menu whose top and bottom separators will be removed * @see #removeTopAndBottomSeparators(JPopupMenu) * @see JMenu#getPopupMenu() * @see javax.swing.JPopupMenu.Separator */ public static void removeTopAndBottomSeparators(JMenu menu) { removeTopAndBottomSeparators(menu.getPopupMenu()); } /** * Removes all top separators from the given pop up menu. * <p> * For example, calling the method on the given menu: * <pre> * Separator * Separator * Menu Entry * Separator * Menu Entry * Separator * Menu Entry * </pre> * would result in: * <pre> * Menu Entry * Separator * Menu Entry * Separator * Menu Entry * </pre> * </p> * * @param popupMenu the pop up menu whose top separators will be removed * @see javax.swing.JPopupMenu.Separator */ public static void removeTopSeparators(JPopupMenu popupMenu) { while (popupMenu.getComponentCount() > 0 && isPopupMenuSeparator(popupMenu.getComponent(0))) { popupMenu.remove(0); } } /** * Convenience method that calls the method {@code removeTopSeparators(JPopupMenu)} with the {@code JPopupMenu} of the given * {@code menu} as parameter. * * @param menu the menu whose top separators will be removed * @see #removeTopSeparators(JPopupMenu) * @see JMenu#getPopupMenu() * @see javax.swing.JPopupMenu.Separator */ public static void removeTopSeparators(JMenu menu) { removeTopSeparators(menu.getPopupMenu()); } /** * Removes all bottom separators from the given pop up menu. * <p> * For example, calling the method on the given menu: * <pre> * Menu Entry * Separator * Menu Entry * Separator * Menu Entry * Separator * Separator * </pre> * would result in: * <pre> * Menu Entry * Separator * Menu Entry * Separator * Menu Entry * </pre> * </p> * * @param popupMenu the pop up menu whose bottom separators will be removed * @see javax.swing.JPopupMenu.Separator */ public static void removeBottomSeparators(JPopupMenu popupMenu) { int indexLastComponent = popupMenu.getComponentCount() - 1; while (indexLastComponent >= 0 && isPopupMenuSeparator(popupMenu.getComponent(indexLastComponent))) { popupMenu.remove(indexLastComponent); indexLastComponent -= 1; } } /** * Convenience method that calls the method {@code removeBottomSeparators(JPopupMenu)} with the {@code JPopupMenu} of the * given {@code menu} as parameter. * * @param menu the menu whose bottom separators will be removed * @see #removeBottomSeparators(JPopupMenu) * @see JMenu#getPopupMenu() * @see javax.swing.JPopupMenu.Separator */ public static void removeBottomSeparators(JMenu menu) { removeBottomSeparators(menu.getPopupMenu()); } /** * Tells whether or not the given {@code component} is a {@code JPopupMenu.Separator}. * * @param component the component that will be checked. * @return {@code true} if the given component is a {@code JPopupMenu.Separator}, {@code false} otherwise. * @see javax.swing.JPopupMenu.Separator * @see #isExtensionPopupMenu(Component) * @see #isExtensionPopupMenuItem(Component) */ public static boolean isPopupMenuSeparator(Component component) { return (component instanceof JPopupMenu.Separator); } }