question: private void addCategoryToTree ( DefaultMutableTreeNode node , String [ ] names ) { if ( names . length == 0 ) { return ; } boolean matched = false ; for ( @ SuppressWarnings ( "unchecked" ) Enumeration < DefaultMutableTreeNode > e = node . children ( ) ; e . hasMoreElements ( ) ; ) { DefaultMutableTreeNode childNode = e . nextElement ( ) ; String nodeName = ( String ) childNode . getUserObject ( ) ; if ( nodeName . equals ( names [ 0 ] ) ) { if ( names . length > 1 ) { addCategoryToTree ( childNode , Arrays . copyOfRange ( names , 1 , names . length ) ) ; matched = true ; } else { } } } if ( ! matched ) { DefaultMutableTreeNode root = node ; for ( int i = 0 ; i < names . length ; i ++ ) { DefaultMutableTreeNode newNode = new DefaultMutableTreeNode ( names [ i ] ) ; root . add ( newNode ) ; root = newNode ; } } }
target:  This recursive method is a hack: DirectoryItems flattens the directory structure, but it provides useful functionality, so this method will reconstruct the directory structure for the JTree.