Components and Peers

Most developers do not have to deal directly with peers. However, a handful of Component methods will behave differently if they are invoked before a component's peer has been created—those methods are listed in Table 11-4.

Peers are created in a component's addNotify method. If it is necessary to invoke one of the methods listed in Table 11-4 before a component's peer has been created, you essentially have two choices. You can either invoke addNotify() directly, which may cause the component's peer to be created, or you can override addNotify() and, after invoking super.addNotify(), call the methods that depend upon the peer's existence. For example, consider the applet listed in Example 11-1, which invokes some of the methods ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition 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.