The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Creating a GUI with JFC/Swing
Lesson: Writing Event Listeners

## Solving Common Event-Handling Problems

> This section discusses problems that you might encounter while handling events.

> Problem: I'm trying to handle certain events from a component, but the component isn't generating the events it should.

> - First, make sure you registered the right kind of listener to detect the events. See whether another kind of listener might detect the kind of events you need.
> - Make sure you registered the listener on the right object.
> - Did you implement the event handler correctly? For example, if you extended an adapter class, then make sure you used the right method signautre. Make sure each event-handling method is `public void`, that the name spelled right and that the argument is of the right type.
> - If you still think that the component isn't generating the events it should, check the Java Developer Connection to see whether this is a known bug.

> Problem: My combo box isn't generating low-level events such as focus events.

> - Combo boxes are compound components -- components implemented using multiple components. For this reason, combo boxes don't fire the low-level events that simple components fire. For more information, see Handling Events on a Combo Box.

> Problem: The document for an editor pane (or text pane) isn't firing document events.

> - The document instance for an editor pane or text pane might change when loading text from a URL. Thus, your listeners might be listening for events on an unused document. For example, if you load an editor pane or text pane with HTML that was previously loaded with plain text, the document will change to an `HTMLDocument` instance. If your program dynamically loads text into an editor pane or text pane, make sure the code adjusts for possible changes to the document (re-register document listeners on the new document, and so on).
> If you don't see your problem in this list, see Solving Common Component Problems.

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.