title: JTree refreshing after setting new jtree model
body: <p>I'm trying to use dynamically JTree component.
  Under root node I have four nodes and one of them ("Operations") can have 0 to many children. This is set by user via editable list in separate window opened on users request. After editing this list user hits button 'Save' and then magic should happen. Edited list is sent to server(on the same machine actually, so it doesn't take to long), the window with list is closed but right before that the main window (with jtree) is told to refresh itself, and I can see that it does what is told in log output, but the changes don't show on the screen.</p>
  
  <p>I am using DefaultTreeModel, this method is called to create model at the beginning(when first opening the window) and after the change to update the new model with new structure.
  with dmtn.getLeafCount() I can see that newly downloaded structure from server is the right one with the changed number of leaves under 'Operations'</p>
  
  <pre><code>public DefaultTreeModel getDataStructure() {
      int dataID = task.getData().getId();
      LoggerUtility.logger.info("Data ID: " + dataID);
      DefaultMutableTreeNode dmtn = Manager.manager.getDataStructure(task.getId());
      LoggerUtility.logger.info("DTMN created "+dmtn.getLeafCount());
  
      return new DefaultTreeModel(dmtn);
  }
  </code></pre>
  
  <p>the method used to refresh the jtree looks like this (it's very messy):</p>
  
  <pre><code>public void updateTree(){
      taskDataTree.setModel(getDataStructure());
      ((DefaultTreeModel)taskDataTree.getModel()).reload();
      this.revalidate();
      this.repaint();
      taskDataTree.revalidate();
      taskDataTree.repaint();
      taskDataTree.updateUI();
      taskDataTree.setVisible(false);
      taskDataTree.setVisible(true);
      jScrollPane2.setViewportView(taskDataTree);
  }
  </code></pre>
  
  <p>It's very messy because I have tried to put in there every possible solution to  my problem that I have found on forums, 
  I also tried with my own treemodel implementation which would call fireTreeStructureChanged(...) but it also didn't change.</p>
  
  <p>I should probably also add that I'm using Netbeans GUI Builder to build my gui although I don't know if it has anything to do with that.</p>
  
  <p>I would be very grateful for any help with that</p>
  
  <p>BR
  Lucja</p>
  
  <p><strong>EDIT!!!</strong>
  I also tried puting it in another thread like that:</p>
  
  <pre><code>public void updateTree() {
  
      SwingWorker sw = new SwingWorker() {
  
          @Override
          protected Object doInBackground() throws Exception {
              taskDataTree.setModel(getDataStructure());
              ((DefaultTreeModel) taskDataTree.getModel()).reload();
              taskDataTree.revalidate();
              taskDataTree.repaint();
              taskDataTree.updateUI();
              taskDataTree.setVisible(false);
              taskDataTree.setVisible(true);
              jScrollPane2.setViewportView(taskDataTree);
              return null;
          }
      };
      sw.execute();
  }
  </code></pre>
  
  <p>but it also didn't help.</p>