public static Set<JComponent> allComponents(JComponent parent){
  Set<JComponent> result=new HashSet<>();
  Deque<JComponent> queue=new LinkedList<>();
  queue.add(parent);
  while (!queue.isEmpty()) {
    JComponent c=queue.removeFirst();
    result.add(c);
    for (    Component c0 : c.getComponents()) {
      if (c0 instanceof JComponent) {
        queue.add((JComponent)c0);
      }
    }
  }
  result.remove(parent);
  return result;
}

public static Set < JComponent > allComponents ( JComponent parent ) { Set < JComponent > result = new HashSet < > ( ) ; Deque < JComponent > queue = new LinkedList < > ( ) ; queue . add ( parent ) ; while ( ! queue . isEmpty ( ) ) { JComponent c = queue . removeFirst ( ) ; result . add ( c ) ; for ( Component c0 : c . getComponents ( ) ) { if ( c0 instanceof JComponent ) { queue . add ( ( JComponent ) c0 ) ; } } } result . remove ( parent ) ; return result ; }
returns a set of all components under the given parent .
