JRootPane: addAncestorListener(AncestorListener listener) : JRootPane « javax.swing « Java by API






JRootPane: addAncestorListener(AncestorListener listener)

 


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

public class Main {
  public static void main (String args[]) {
    JFrame f = new JFrame("Ancestor Sampler");
    f.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");
      }
    };
    f.getRootPane().addAncestorListener(ancestorListener);
    f.getRootPane().setVisible(false);
    f.getRootPane().setVisible(true);
    f.setSize (300, 200);
    f.setVisible (true);
  }
}

   
  








Related examples in the same category

1.JRootPane.FRAME
2.JRootPane: getAccessibleContext()
3.JRootPane: getContentPane()
4.JRootPane: setDefaultButton(JButton defaultButton)
5.JRootPane: setWindowDecorationStyle(int style)