Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2004

Tip: Looking for answers? Try searching our database.

JTree: Catching the setUserObject() call in a DefaultMutableTreeNode

Thread view: 
Chris Murphy - 01 Oct 2004 01:07 GMT
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?

In the case in question I want the root DefaultMutableTreeNode to
always contain the userObject "Values". Somewhere in the code "Values"
is being replaced by null. How do I find out where this is? (Same
question!).

I know how to replace the Swing version of DefaultMutableTreeNode with
one I have written, so that I can debug this action for every single
DefaultMutableTreeNode in every JTree. But really I am hoping that
there is some quite obvious way, using the JTree API, that I have
overlooked.

thanks - Chris Murphy
Paul Lutus - 01 Oct 2004 05:16 GMT
> 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?

1. Hard way: examine every node in the tree. When you encounter a null, you
stop.

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

> I know how to replace the Swing version of DefaultMutableTreeNode with
> one I have written, so that I can debug this action for every single
> DefaultMutableTreeNode in every JTree. But really I am hoping that
> there is some quite obvious way, using the JTree API, that I have
> overlooked.

That is how you do it -- derive your own class.

Signature

Paul Lutus
http://www.arachnoid.com

Chris Murphy - 04 Oct 2004 08:05 GMT
> 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
Christian Kaufhold - 14 Oct 2004 15:31 GMT
> 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?

The only visible occurance of setUserObject in the standard classes
is in DefaultTreeModel.valueForPathChanged. Try overriding it.

Christian


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.