code: public static boolean addSeparatorIfNeeded(JPopupMenu popupMenu) {
          final int menuComponentCount = popupMenu.getComponentCount();
          if (menuComponentCount == 0) {
              return false;
          }
          final Component lastMenuComponent = popupMenu.getComponent(menuComponentCount - 1);
          if (isPopupMenuSeparator(lastMenuComponent)) {
              return false;
          }
          popupMenu.addSeparator();
          return true;
      }
docs: Appends a separator to the end of the menu if it exists at least one non separator menu component immediately before and
  if there isn't, already, a separator at the end of the menu.
  
  @param popupMenu the pop up menu that will be processed
  @return {@code true} if the separator was added, {@code false} otherwise.
  @see javax.swing.JPopupMenu.Separator