> I am trying to debug a JTree. Specifically a particular
> DefaultMutableTreeNode is having its userObject property set to null.
> What is the easiest way that I can catch the set occuring?

Signature
Paul Lutus
http://www.arachnoid.com
> 1. Hard way: examine every node in the tree. When you encounter a null, you
> stop.
Fair enough, but I need the event at which time this happens, or some
type of method overriding, or replacement ...
> 2. Less hard: trap all assignments to the node in question and examine them.
> To trap them, override the assignment method in a class derived from
[quoted text clipped - 7 lines]
>
> That is how you do it -- derive your own class.
I actually meant replace rather than override, using a bootclasspath
-X option when running Java. You just get Sun's source code and alter
it to output debugging messages.
However I tried this and peeked into (ie. wrote debugging lines in)
the method DefaultMutableTreeNode.setUserObject(). The problem was
that the userObject property seems to be being set some other way.
Will get back to here when I find the way to do this, or work out my
silly mistake!
- Chris Murphy
Paul Lutus - 04 Oct 2004 08:47 GMT
/ ...
>> That is how you do it -- derive your own class.
>
> I actually meant replace rather than override, using a bootclasspath
> -X option when running Java.
With only the slighest exaggeration I can say the entire point of
object-oriented programming is to be able to modify an existing class by
extending it and overriding selected methods. That way you don't have to
try to hack the original class source file. In modern times, the latter is
unbelievably primitive, as well as unnecessary.
> You just get Sun's source code and alter
> it to output debugging messages.
Sounds simple. But it is a VBI(tm).
> However I tried this and peeked into (ie. wrote debugging lines in)
> the method DefaultMutableTreeNode.setUserObject(). The problem was
> that the userObject property seems to be being set some other way.
> Will get back to here when I find the way to do this, or work out my
> silly mistake!
Reconsider your entire approach.

Signature
Paul Lutus
http://www.arachnoid.com
Chris Murphy - 04 Oct 2004 17:02 GMT
Hi Paul,
I was talking about debugging something, not the design of the code.
The replacement of Sun's code is only a temporary measure to find
something out.
I'm actually right into OO programming, although I seldom use
inheritance.
Chris Murphy - 14 Oct 2004 04:09 GMT
> silly mistake!
This thread continued here, where a brute force method/s of debugging
employed:
http://groups.google.com/groups?hl=en&lr=&threadm=5107bf74.0410081552.756543e1%4
0posting.google.com&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26q%3DChris%2BMurphy%2
6btnG%3DSearch%26meta%3Dgroup%253Dcomp.lang.java.gui
- Chris Murphy