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: application Task problem - updating JTree

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wink application Task problem - updating JTree

    Hi all , i am running to a problem , maybe one of you can find the problem .
    i have a JTree , and i want to update him in a Thread , since i want it to change the progress bar .
    i used the Netbeans progress bar .
    everything works fine , my only problem is , that once the Task is done , i see the JTree return to be empty .
    and not saving the root i add in the succeeded function .
    the code :
    // this is the button i press to add to start the Task
        @Action public Task  AddToList(){
            Task newTask = new runThreadFolderBrowser(getApplication());
            return newTask;
        }
     
      private class runThreadFolderBrowser extends org.jdesktop.application.Task<Object, Void> {
             private DefaultMutableTreeNode saveTreeNode;
               // <editor-fold defaultstate="collapsed" desc="Constructor of the Class">
             runThreadFolderBrowser(org.jdesktop.application.Application app){
                 // the Constructor Runs on EDT , and can Update the GUI
                 super(app);
                 treeComponents.setEditable(true);
             } 
             @Override protected Object doInBackground(){
                 CheckListItem[] allFoldersItems =  BackupServerSettings.Instance.researchBackupFolder();
                 DefaultMutableTreeNode rootNode  = new DefaultMutableTreeNode("Backup Server");
                 try {
                   succeeded(rootNode);
                    return null;
                 } catch ( NullPointerException noFolder_noConnection){
                    return null;
                 }
             }
     
             @Override protected void succeeded(Object rootNode){
                 DefaultTreeModel treemodel = (DefaultTreeModel) treeComponents.getModel(); // get the current JTree
                 treemodel.setRoot((DefaultMutableTreeNode)rootNode);  // change the Root folders of the current tree .
                 treeComponents.setRootVisible(true);
                 treeComponents.repaint(); // repaint the JTree
             }
     
             @Override protected void finished(){
             }
         }


  2. #2
    Junior Member
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: application Task problem - updating JTree

    ok , so problem is solved .
    i had to change the return from null to rootNode , in the doIn Background function .
    but thanks .

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: application Task problem - updating JTree

    Hello idandush. Welcome to the Java Programming Forums.

    I'm glad you solved your problem! I will mark this thread as solved.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.