In a browser if I’m using javascript it’s fairly straight forward to traverse the DOM. Unpacking it from the top down is just a series of calls, and finding individual elements is easy because of id# tags.
Swing components have a treelike structure similar to HTML. What’s the best methodology for traversing that structure to find objects inside of it? Or should I simply stick to creating local field references to the objects that I care about?
Assuming you have a user interface that has data in it, and some code that’s interested in querying those components to find out what their state is, how would you manage “finding” those components in the Swing DOM?
A HTML DOM is a tree data structure, which doesn’t provide much behavior, and that uses node types that are not under your control.
A Swing tree of components is a tree of rich objects, containing objects of types that you create, and which should provide the behavior you need. You should apply the OO principles to the elements of this tree (panels, etc.): encapsulation, law of demeter, composition, etc.
You shouldn’t have to traverse a tree of Swing components to find the one you want. This would be a sign of poor design and lack of encapsulation. The elements of the tree should collaborate, reference each other, call appropriate methods to do their job.