Determining When a Component Is Added or Removed from a Container : Panel « Swing JFC « Java






Determining When a Component Is Added or Removed from a Container

  

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);
  }
}

   
    
  








Related examples in the same category

1.Panel with background imagePanel with background image
2.Getting the Child Components of a Container
3.Retrieve all components individually:
4.Horizontal Split Pane based on JPanel