Using Swing Event Listeners

Like their AWT counterparts, Swing event listeners are interfaces. Unlike AWT, Sun hasn't yet implemented many adapter classes, so usually you'll need to override every listener method to implement a listener. To implement an AncestorListener (which has three methods), for example, you might write

public class myAncestorListener implements AncestorListener {
  public void ancestorAdded(AncestorEvent e) {
    // ignore this one
  }
  public void ancestorRemoved(AncestorEvent e) {
    // don't care about this one either
  }
  public void ancestorMoved(AncestorEvent e) {
    // do something in this case
    Here is code to handle the case of a moving ancestor
  }
}
					

Note

In GUI jargon, an ancestor is a member of the path of containers that goes ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.