Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Need help filling a jtree using recursion

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help filling a jtree using recursion

    Okay so I am passing a list<string> full of classes. These classes are coming from a jar. Anyways my question is how can I take my file paths and organize them into a jtree. I have tried for so long but this recursion is kicking my butt and hurts my head.

    Give you an idea of what I created.

    public static DefaultMutableTreeNode addNodesMe(DefaultMutableTreeNode node, List<String> classes) {

    }

    We need that node to start as null and end up being something we can plug into our jtree. It just has to put every thing into the correct folders.

    Here is an example of the strings I am recieving.
    com/Tarnadas/ImOnAHorse/Metrics$1.class
    com/Tarnadas/ImOnAHorse/Metrics$Graph.class
    com/Tarnadas/ImOnAHorse/Metrics$Plotter.class
    com/Tarnadas/ImOnAHorse/Metrics.class
    com/Tarnadas/ImOnAHorse/Config.class
    com/Tarnadas/ImOnAHorse/MagicSaddle$Saddle.class
    com/Tarnadas/ImOnAHorse/MagicSaddle.class
    com/Tarnadas/ImOnAHorse/ImOnAHorse.class
    com/Tarnadas/ImOnAHorse/MagicLeash$1.class
    com/Tarnadas/ImOnAHorse/MagicLeash$2.class
    com/Tarnadas/ImOnAHorse/MagicLeash.class
    com/Tarnadas/ImOnAHorse/MagicArmor$Armor.class
    com/Tarnadas/ImOnAHorse/MagicArmor.class
    com/Tarnadas/ImOnAHorse/MagicEgg.class
    com/Tarnadas/ImOnAHorse/Exceptions/NotEnoughFuelException.class
    com/Tarnadas/ImOnAHorse/Exceptions/DispenserAlreadyRegisteredException.class
    com/Tarnadas/ImOnAHorse/Exceptions/PlayerIsNotAddingDispenserException.class
    com/Tarnadas/ImOnAHorse/Exceptions/LeashInventoryFullException.class
    com/Tarnadas/ImOnAHorse/Exceptions/PlayerIsAlreadyAddingDispenserException.class
    com/Tarnadas/ImOnAHorse/Exceptions/InventoryFullException.class
    com/Tarnadas/ImOnAHorse/Exceptions/NotYourHorseException.class
    com/Tarnadas/ImOnAHorse/Exceptions/CheckpointDoesNotExistException.class
    com/Tarnadas/ImOnAHorse/Exceptions/HorseAlreadyRegisteredException.class
    com/Tarnadas/ImOnAHorse/Exceptions/ParkourDoesNotExistException.class
    com/Tarnadas/ImOnAHorse/Exceptions/FinishNotSetException.class
    com/Tarnadas/ImOnAHorse/Exceptions/NoItemInHandException.class
    com/Tarnadas/ImOnAHorse/Exceptions/PlayerIsMountedException.class
    com/Tarnadas/ImOnAHorse/Exceptions/NoCustomNameSetException.class
    com/Tarnadas/ImOnAHorse/Exceptions/PlayerAlreadyInParkourException.class
    com/Tarnadas/ImOnAHorse/Exceptions/PlayerNotInParkourException.class
    com/Tarnadas/ImOnAHorse/Exceptions/CheckpointAlreadyExistsException.class
    com/Tarnadas/ImOnAHorse/Listeners/MagicDispenserListener.class
    com/Tarnadas/ImOnAHorse/Listeners/HorseListener.class
    com/Tarnadas/ImOnAHorse/Listeners/CraftListener.class
    com/Tarnadas/ImOnAHorse/Listeners/WorldGuardListener.class
    com/Tarnadas/ImOnAHorse/Listeners/ParkourSignListener.class
    com/Tarnadas/ImOnAHorse/Listeners/ParkourListener$1.class
    com/Tarnadas/ImOnAHorse/Listeners/ParkourListener$2.class
    com/Tarnadas/ImOnAHorse/Listeners/ParkourListener$3.class
    com/Tarnadas/ImOnAHorse/Listeners/ParkourListener$4.class
    com/Tarnadas/ImOnAHorse/Listeners/ParkourListener$5.class
    com/Tarnadas/ImOnAHorse/Listeners/ParkourListener$6.class
    com/Tarnadas/ImOnAHorse/Listeners/ParkourListener.class
    com/Tarnadas/ImOnAHorse/Listeners/LeashListener.class
    com/Tarnadas/ImOnAHorse/parkour/Checkpoint.class
    com/Tarnadas/ImOnAHorse/parkour/ParkourSign.class
    com/Tarnadas/ImOnAHorse/parkour/Parkour$1.class
    com/Tarnadas/ImOnAHorse/parkour/Parkour$2.class
    com/Tarnadas/ImOnAHorse/parkour/Parkour$3.class
    com/Tarnadas/ImOnAHorse/parkour/Parkour$4.class
    com/Tarnadas/ImOnAHorse/parkour/Parkour$5.class
    com/Tarnadas/ImOnAHorse/parkour/Parkour.class
    com/Tarnadas/ImOnAHorse/parkour/MagicDispenser$ProjectileType.class
    com/Tarnadas/ImOnAHorse/parkour/MagicDispenser.class


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    610
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Need help filling a jtree using recursion

    Hi, post your code. It's hard to give you hints without seeing the code.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Need help filling a jtree using recursion

    Quote Originally Posted by TroostMe View Post
    Here is an example of the strings I am recieving.
    com/Tarnadas/ImOnAHorse/Metrics$1.class
    com/Tarnadas/ImOnAHorse/Metrics$Graph.class
    com/Tarnadas/ImOnAHorse/Metrics$Plotter.class
    com/Tarnadas/ImOnAHorse/Metrics.class
    com/Tarnadas/ImOnAHorse/Config.class
    com/Tarnadas/ImOnAHorse/MagicSaddle$Saddle.class
    com/Tarnadas/ImOnAHorse/MagicSaddle.class
    com/Tarnadas/ImOnAHorse/ImOnAHorse.class
    .....
    So you have these strings and your goal is to have a JTree that displays something like this?

    com
        Tarnadas
            ImOnAHorse
                Metrics$1.class
                Metrics$Graph.class
                    .....

    First of all, since each string has a complete path, one thing is clear: for each string you have to "navigate" into JTree, starting from the root, to find the node under which to put the filename. Eventually creating the intermediate nodes if not present.

    To be more clear: when you arrive at string "com/Tarnadas/ImOnAHorse/Exceptions/NotEnoughFuelException.class", in the JTree you can find the "com" and under it the "Tarnadas", and then the "ImOnAHorse" nodes. But you have to create the "Exceptions" node before to put into it the "NotEnoughFuelException.class" node.

    All this has, by itself, nothing to do with "recursion".
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

Similar Threads

  1. Filling a Shape with lines
    By JAPA1972 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 29th, 2013, 05:29 PM
  2. Filling the frame
    By Metadeth in forum AWT / Java Swing
    Replies: 2
    Last Post: July 11th, 2011, 03:28 PM
  3. Filling Arrays
    By av8 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 25th, 2011, 11:41 PM
  4. Chessboard filling issue
    By olemagro in forum AWT / Java Swing
    Replies: 7
    Last Post: January 23rd, 2010, 06:07 PM
  5. Filling an Array?
    By Bascotie in forum Collections and Generics
    Replies: 5
    Last Post: October 14th, 2009, 06:27 PM