title: What is an HierarchyEvent in Java/Swing?
body: <p>I'm refreshing my knowledge of Java by looking through some of the java tutorials. On <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/jcomponent.html" rel="nofollow">this</a> page I saw the addHierarchyListener and removeHierarchyListener method.</p>
  
  <p>I've searched the API and google and this website. All I got was this: </p>
  
  <blockquote>
    <p>Adds or removes the specified hierarchy listener to receive hierarchy changed events from this component when the hierarchy to which this container belongs changes. If listener l is null, no exception is thrown and no action is performed.<br>
    ~<a href="http://docs.oracle.com/javase/tutorial/uiswing/components/jcomponent.html#eventapi" rel="nofollow">Java Tutorial</a> </p>
  </blockquote>
  
  <p>And the API notes the listener:</p>
  
  <blockquote>
    <p>The listener interface for receiving hierarchy changed events. The class that is interested in processing a hierarchy changed event should implement this interface. The listener object created from that class is then registered with a Component using the Component's addHierarchyListener method. <em>When the hierarchy to which the Component belongs changes</em>, the hierarchyChanged method in the listener object is invoked, and the HierarchyEvent is passed to it.<br>
    Hierarchy events are provided for notification purposes ONLY; The AWT will automatically handle changes to the hierarchy internally so that GUI layout, displayability, and visibility work properly regardless of whether a program registers a HierarchyListener or not.<br>
    ~<a href="http://docs.oracle.com/javase/7/docs/api/java/awt/event/HierarchyListener.html" rel="nofollow">JavaAPI#HierarchyEventListener</a></p>
  </blockquote>
  
  <p>And Later On the events:</p>
  
  <blockquote>
    <p>Hierarchy events are provided for notification purposes ONLY. The AWT will automatically handle changes to the hierarchy internally so that GUI layout and displayability works properly regardless of whether a program is receiving these events or not.<br>
    This event is generated by a <em>Container object (such as a Panel) when the Container is added, removed, moved, or resized, and passed down the hierarchy</em>. It is also generated by a Component object when that object's addNotify, removeNotify, show, or hide method is called. The ANCESTOR_MOVED and ANCESTOR_RESIZED events are dispatched to every HierarchyBoundsListener or HierarchyBoundsAdapter object which registered to receive such events using the Component's addHierarchyBoundsListener method. (HierarchyBoundsAdapter objects implement the HierarchyBoundsListener interface.) The HIERARCHY_CHANGED events are dispatched to every HierarchyListener object which registered to receive such events using the Component's addHierarchyListener method. Each such listener object gets this HierarchyEvent when the event occurs.
    ~<a href="http://docs.oracle.com/javase/7/docs/api/java/awt/event/HierarchyEvent.html" rel="nofollow">JavaAPI#HierarchyEvent</a></p>
  </blockquote>
  
  <p>My understanding of hierarchy outside of Java is that they specify when one thing is above another etc. Like Maslow's Hierarchy of needs (some needs are above others <em>in importance</em>). So I know what the word means, but what does it mean for a component to belong to a hierarchy? Is it 'owned' by another component, or is one the parent?</p>
  
  <p>THe only event out of <em>added, removed, moved, or resized</em> I can envisionage happening at runtime is the resizing event...but when would this matter?</p>
  
  <p>Would an example be of a JFrame being resized, and then via a HierarchyEvent telling a JPanel to change the layout to fit the new size?</p>
  
  <p>Could someone help explain them?</p>