code: public static void sortMenu(BaseComponent parent, int startIndex, int endIndex) {
          List<BaseComponent> items = parent.getChildren();
          int bottom = startIndex + 1;
  
          for (int i = startIndex; i < endIndex;) {
              BaseComponent item1 = items.get(i++);
              BaseComponent item2 = items.get(i);
  
              if (item1 instanceof BaseMenuComponent && item2 instanceof BaseMenuComponent && ((BaseMenuComponent) item1)
                      .getLabel().compareToIgnoreCase(((BaseMenuComponent) item2).getLabel()) > 0) {
                  parent.swapChildren(i - 1, i);
  
                  if (i > bottom) {
                      i -= 2;
                  }
              }
          }
      }
docs: Alphabetically sorts a range of menu items.
  
  @param parent Parent whose children are to be sorted alphabetically.
  @param startIndex Index of first child to be sorted.
  @param endIndex Index of last child to be sorted.