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
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