PDA

View Full Version : Internal Views


dortman
Sep 23rd, 2004, 07:40 PM
First, a quick thanks. I have a demo application up and running with very little time invested. It's not much more complex than the usual "Hello World" endeavor, but I was pleased with how quickly it came together.

The main window of the my application has a JList or a JTree on the left of the window. I then have many classes which extend JComponent. These contain a few widgets, a JTable, etc - and exist to display some relevant data. Upon selection of an item from the JList/JTree, a corresponding JComponent will be displayed in the right portion of the screen.

I was unable to find any classes in the framework to utilize for such a relationship. It's quite possible that I overlooked a viable solution. I played around with the CompondForm and NestableForm classes - but they didn't seem to be what I needed. I have it working fine now using a few classes which I implemented by simply extending Jcomponent, but then I end up losing much of the framework functionality.

Are there some classes I should be looking at?

Thanks,
-Dave

Keith Donald
Sep 23rd, 2004, 08:59 PM
In general we've favored composition over inheritence for returning complex controls that consist of more lower-level controls assembled together. This is the whole purpose of the ControlFactory interface, and many framework classes, for example ApplicationDialog and AbstractForm implement this interface. This -- from my experience -- has proven more flexible than extending the JComponent hierarchy, it also offers more encapsulation.

I'd just invite you to poke around the various out-of-the-box classes of the framework to see this in action, and see how you can leverage it. For example, you could define a View definition (see Petclinic for an example of how to do this) declaratively, and the framework will handle dropping the component produced by the View's getControl() method in a internal frame displayed within in center page area of the application. The component returned can be anything: a out-of-the-box Swing class, or your own control you develop. That's the power of composition/encapsulation ;-)