Determining When a Component Is Added or Removed from a Container

A container fires a container event whenever a component is added or removed.
// Create a listen for container events ContainerListener listener = new ContainerAdapter() { public void componentAdded(ContainerEvent evt) { // Get component that was added Component c = evt.getChild(); } public void componentRemoved(ContainerEvent evt) { // Get component that was removed Component c = evt.getChild(); } }; // Register the listener with the container container.addContainerListener(listener);

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.