1

I have a large JTree and I need to expand thousands of nodes all at once. Right now, that is taking a long time. I think it's because it's firing notifications and doing all the work for every one. Is there some way to tell it to expand all the nodes in a batch so it only has to update things once afterwards?

Or some other way to make expanding lots of nodes in a batch faster?

mentics
  • 6,852
  • 5
  • 39
  • 93
  • Given that we haven't posted your SSCCE (http://sscce.org) showing the code you use to expand the nodes I don't know how we can make suggestions to do something different. – camickr Nov 23 '10 at 02:04

1 Answers1

0

Have you tried disabling the tree's event listeners? That way it won't fire off events every time you modify the tree. Something like this:

setVisible(false);
tree.removeTreeWillExpandListener(this);
tree.removeTreeSelectionListener(this);

//modify the tree

tree.addTreeSelectionListener(this);
tree.addTreeWillExpandListener(this);
setVisible(true);
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
  • 1
    If I remove all the listeners, then the tree won't expand. And it appears that once I do try to expand it after that, it fires all the events or something... it kicks off lots of selection events when there are expand events which is frustrating. – mentics Nov 23 '10 at 00:30
  • The tree will probably fire events... but there will be nothing to listen to them. You can still expand the tree without the listeners. You're just adding them back after expansion. – Vivin Paliath Nov 23 '10 at 04:45