Determining When a Component Is Added or Removed from a Container : ContainerListener « Swing Event « Java Tutorial






import java.awt.Component;
import java.awt.event.ContainerAdapter;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;

import javax.swing.JFrame;

public class Main {
  public static void main() {

    ContainerListener listener = new ContainerAdapter() {
      public void componentAdded(ContainerEvent evt) {
        
        Component c = evt.getChild();
      }

      public void componentRemoved(ContainerEvent evt) {
        
        Component c = evt.getChild();
      }
    };

    JFrame frame = new JFrame();
    frame.addContainerListener(listener);
  }
}








15.11.ContainerListener
15.11.1.How to Write a Container ListenerHow to Write a Container Listener
15.11.2.ContainerListener and ContainerEventContainerListener and ContainerEvent
15.11.3.Using ComponentListener to catch the JFrame Maximization event
15.11.4.Determining When a Component Is Added or Removed from a Container