Automatic expansion of "inserted" JTree nodes

D

dablick

I want newly inserted nodes in a JTree to be expanded as they are inserted.

This doesn't seem to be the default and it's not clear to me the right way
to go about this.

- Is there a component property i can set to make this the default or

- Do I have to have a "TreeModel listener" for isnserts that does this?

+ The problem with having a listener is that you have to guarantee that
the JTree's
TreeModel listener gets invoked BEFORE your expansion listener
because otherwise
your listener will try to "expand" a node before it's actually
created by the JTree listener.
The Sun source code does say that listeners are invoked in "reverse"
order but even
setting the Treemodel (which sets up the listener) AFTER the
"expanding" listener
doesn't seem to work (I get a mysterious, hard-to-diagnose illegal
cast)

+ Is there a way to short capture the insert event delivered to the
JTree's treemodel
listener, Run the listener's handler and then do the expand?

It occurred to me that I might be able to subclass the JTrees
listener and then just
have code for the "nodes inserted" event call super() but... the
JTree's listener is an
inner class of JTree I think.

Maybe subclass JTree to do this?

There's got to be an easy way to do this that i'm just missing. Any help
would be appreciated.

Thanks,

Dave Blickstein
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top