title: Composite pattern in Swing
body: <p>This is basically a architectural question.</p>
  
  <p>I want to implement <a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow">composite pattern</a> in handling Swing components; that is, I want to combine several components with their listeners and logic behind a single component for easier handling.</p>
  
  <p>Consider for example a simple directory browser; say, a JTree in JScrollPane with some logic which handles populating filenames as user expands JTree nodes. How would you implement that?</p>
  
  <p>Do you extend JScrollPane and add JTree and so on in constructor, and then your application deals with JScrollPaneExtended class? Or do you extend, say, JPanel or JComponent? Or do you stitch all those classes together in a method you call when you're populating your JFrame? Or something else? And why?</p>
  
  <p>I'm basically looking for a rough guideline on what others use; I'd obviously like to deal with some form of JComponent for easier handling in constructing GUI, however somehow it doesn't feel right to extend topmost component (JScrollPane in this example) just to have someplace to put glue code.</p>