JPanel: addAncestorListener(AncestorListener lis) : JPanel « javax.swing « Java by API






JPanel: addAncestorListener(AncestorListener lis)

  
import javax.swing.JFrame;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;

public class MainClass {

  public static void main(String[] a) {
    JFrame frame = new JFrame("Ancestor Sampler");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    AncestorListener ancestorListener = new AncestorListener() {
      public void ancestorAdded(AncestorEvent ancestorEvent) {
        System.out.println("Added");
      }

      public void ancestorMoved(AncestorEvent ancestorEvent) {
        System.out.println("Moved");
      }

      public void ancestorRemoved(AncestorEvent ancestorEvent) {
        System.out.println("Removed");
      }
    };
    frame.getRootPane().addAncestorListener(ancestorListener);
    frame.setSize(300, 200);
    frame.setVisible(true);
    frame.getRootPane().setVisible(false);
    frame.getRootPane().setVisible(true);
  }
}


           
         
    
  








Related examples in the same category

1.JPanel: addContainerListener(ContainerListener l)
2.JPanel: addMouseListener(MouseListener mous)
3.JPanel: addMouseMotionListener(MouseMotionListener lis)
4.JPanel: addKeyListener(KeyListener l)
5.JPanel: getFocusTraversalKeys(int id)
6.JPanel: isFocusCycleRoot()
7.JPanel: paintComponent(Graphics g)
8.JPanel: repaint()
9.JPanel: setBackground(Color c)
10.JPanel: setBorder(Border border)
11.JPanel: setComponentPopupMenu(JPopupMenu popup)
12.JPanel: setFocusCycleRoot(boolean value)
13.JPanel: setFocusTraversalPolicyProvider(boolean value)
14.JPanel: setLayout(null)
15.JPanel: setOpaque(boolean isOpaque)
16.JPanel: setPreferredSize(Dimension preferredSize)
17.JPanel: setToolTipText(String htmlString)
18.extends JPanel