6 Replies Latest reply: Sep 27, 2012 10:18 AM by boffman RSS

    H e l p !!! Fill JTree recursivly

    boffman
      Hi,

      I'm looking for a simple adequate example to fill a jtree recursivly?

      cheers,
      Bernhard

      Edited by: boffman on 26.09.2012 12:34

      Edited by: boffman on 26.09.2012 13:07
        • 1. Re: H e l p !!! Fill JTree recursivly
          800268
          import java.awt.EventQueue;
          
          import javax.swing.JFrame;
          import javax.swing.JScrollPane;
          import javax.swing.JTree;
          import javax.swing.tree.DefaultMutableTreeNode;
          import javax.swing.tree.DefaultTreeModel;
          
          public class RecursiveJTree {
              public static void main(String[] args) {
                  EventQueue.invokeLater(new Runnable() {
                      @Override
                      public void run() {
                          JFrame frame = new JFrame("Test");
                          frame.setDefaultCloseOperation(
                                  JFrame.DISPOSE_ON_CLOSE);
                          frame.getContentPane().add(
                                  new JScrollPane(new JTree(
                                      new DefaultTreeModel(createTreeRecursively(
                                          4, new DefaultMutableTreeNode("Root"))))));
                          frame.pack();
                          frame.setLocationRelativeTo(null);
                          frame.setVisible(true);
                      }
          
                      private DefaultMutableTreeNode createTreeRecursively(
                              int count, DefaultMutableTreeNode parent) {
                          for (int i = 0; i < count; i++) {
                              DefaultMutableTreeNode child = new DefaultMutableTreeNode(i);
                              parent.add(createTreeRecursively(count - 1, child));
                          }
          
                          return parent;
                      }
                  });
              }
          }
          See also http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html#create
          • 2. Re: H e l p !!! Fill JTree recursivly
            boffman
            Hi Walter,

            so far so good :-) but what I really need ist a recursiv JTree with a select connect by prior?

            cheers,
            Bernhard
            • 3. Re: H e l p !!! Fill JTree recursivly
              DrClap
              Why don't you post the entire specs for the program you want to have somebody write for you, then? Revealing them one at a time is one way to annoy people.
              • 4. Re: H e l p !!! Fill JTree recursivly
                boffman
                ...sorry I'm new to Java and I thought this is a comon problem with lot's of examples?
                • 5. Re: H e l p !!! Fill JTree recursivly
                  800268
                  There are plenty example how to use JTrees, there a probably plenty of example how to use SQL (specifically about "select connect by prior" I have no idea).

                  Your job (should you choose to accept it) is to learn from those examples and build a program which combines them.
                  • 6. Re: H e l p !!! Fill JTree recursivly
                    boffman
                    Ok thanks anyway