Java JPopupMenu addSeparatorIfNecessary(JPopupMenu popup)

Here you can find the source of addSeparatorIfNecessary(JPopupMenu popup)

Description

Adds a separator to the popup menu if there are menu items on it already.

License

Open Source License

Parameter

Parameter Description
popup the popup menu.

Declaration

public static void addSeparatorIfNecessary(JPopupMenu popup) 

Method Source Code

//package com.java2s;
import javax.swing.*;

public class Main {
    /**//from ww w .  j  av  a2 s .co  m
     * Adds a separator to the popup menu if there are menu items on it already.
     *
     * @param popup the popup menu.
     */
    public static void addSeparatorIfNecessary(JPopupMenu popup) {
        int count = popup.getComponentCount();
        if (count > 0
                && !(popup.getComponent(count - 1) instanceof JSeparator)) {
            popup.addSeparator();
        }
    }
}

Related

  1. addMenuItems(JPopupMenu menu, JComponent... items)
  2. addOption(JPopupMenu popupMenu, String text, String key, ActionListener actionListener)
  3. addPopup(Component component, final JPopupMenu popup)
  4. addPopup(Component component, final JPopupMenu popup)
  5. addPopup(final Component c, final JPopupMenu m)
  6. addSeparatorIfNecessary(JPopupMenu popup)
  7. addSeparatorIfNeeded(JPopupMenu popupMenu)
  8. applyDefaultProperties(final JPopupMenu comp)
  9. attachPopupMenu(final JComponent component, final JPopupMenu popupMenu)