code: private static void getLeafNodes(
          TreeModel treeModel, Object node, Collection<Object> leafNodes)
      {
          if (node == null)
          {
              return;
          }
          int childCount = treeModel.getChildCount(node);
          if (childCount == 0)
          {
              leafNodes.add(node);
          }
          else
          {
              for (int i = 0; i < childCount; i++)
              {
                  Object child = treeModel.getChild(node, i);
                  getLeafNodes(treeModel, child, leafNodes);
              }
          }
      }
docs: Recursively collect all leaf nodes in the given tree model that are
  descendants of the given node.
  
  @param treeModel The tree model
  @param node The node to start the search from
  @param leafNodes The leaf nodes