Hello all,
First off, I'm building a Swing app using the 1.4.1 JDK. The app has tabbed panes where each pane has complicated JPanels (containing more tabbed panes, tree views, and tables) where events in one pane need to be propagated to objects in other panes. The objects intending to generate and listen to the events are created by their immediate containers which are far down the hierarchy in the panes. Currently they don't have direct references to objects in other panels. Our current quick and dirty answer is to use getParent() in the event handler to go up the chain to a common parent container and then make a straight call that propagates down to the listening component. But I don't like that because it relies on the hierarchy staying static, which I'm not sure is true and seeing things like getParent().getParent().getParent().getParent() triggers a red flag. Other ideas include a application wide 'uber-event' handler that everything uses, a more specific dispatcher-type-object that gets passed around and handles the events, and some other ideas. Does anyone out there have a good example of or guidelines on how to manage this sort of thing? How do other people deal with event handling in complicated applications?
Secondly, in this application we need to put various cominations of JLabels and JTextFields, JLists, etc into a single object reference. The idea is that we need to be able to take any one of our system's business object attributes which are of various types (text, datetimes, addresses, enumerated distances, multi-valued text, currency ranges, etc) and present them in the UI. Our current thinking is to extend JPanel and have each child know how to take a specific type of attribute and put whatever it needs to visually represent the attribute onto itself. A factory would then be able to take an attribute and return a JPanel that could be drawn pretty much anywhere in the application. Does that seem like a decent idea or is there another container/component besides JPanel that we should consider? Or is there an altogether different strategy that might be better?
Any thoughts are appreciated.
Thanks,
Chris