0

Hello I have question regarding saving expansion state when change DefaultTreeModel. Currently I have a jTree which looks like this: enter image description here

If I select an item from the left JList and select a TestGr from right Jtree and click on Add Test Case button it will add the selected items to the DefaultTreeModel. Doing this will collapse the tree: enter image description here

I would like to somehow save the previous expansion state and just update the tree to show the newly added element like this for example: enter image description here

My goal is to save the previously expanded state which ever that may be and when I add elements to TestGr, everything which was expanded, should stay expanded and update itself with the new element. Does anyone have any idea how might i achieve this? I have tried the solution from store state/expanded nodes of a jtree for restoring state but it's not suitable because when i update my DefaultTreeModel, the row count gets updated too and it expands the wrong rows. Thank you in advance for a hint.

stewazy
  • 139
  • 1
  • 3
  • 8

1 Answers1

0

Solution is to use DefaultTreeModel reload method, but for a specific node. for Example:

DefaultTreeModel model;
DefaultMutableTreeNode node;
//Initialize or change model
model.reload(node);
enter code here
stewazy
  • 139
  • 1
  • 3
  • 8