Question

I have a JTree in my swing app, to display a long list of data (int tree mode).

the issue is that TreeModel loading all items during initialization and I don't need to load them all. in one screen only 100 of them are displayable so no point to load thousands of data to show only 100 of them in one screen.

Question: is there any way to do kind of lazy initialization in TreeModel and retrieve data whenever needed ?

Thanks All

Was it helpful?

Solution

TreeWillExpandListener See for example this

OTHER TIPS

I am assuming you're using the DefaultTreeModel.

I had solved such a problem by implementing a custom TreeModel. It may seem complicated, but once you get into it you see that it's not that bad. You have only 8 methods to implement and most of them are quite trivial if you already have a tree-like data structure.

The main benefit of this approach is that you get total control over the underlying model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top