Solving Common Event-Handling Problems

 <  Day Day Up  >  

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.

Solution 1: 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.

Solution 2: Make sure you registered the listener on the right object.

Solution 3: Did you implement the event handler correctly? For example, if you extended an adapter class, then make sure you used the right method signature. Check that each event-handling method is public void , with the name spelled correctly, and the argument is of the right type.

If you still think that the component isn't generating the events it should, refer to the Java Developer Connection to check whether this is a known bug online at: http://developer.java.sun.com/developer/bugParade/.

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

Solution: 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 How to Use Combo Boxes (page 176) in Chapter 7.

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

Solution: 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 HTML into an editor pane or text pane 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 (reregister document listeners on the new document, and so on).

If you don't see your problem in this list, refer to Solving Common Component Problems (page 735).

 <  Day Day Up  >  


JFC Swing Tutorial, The. A Guide to Constructing GUIs
The JFC Swing Tutorial: A Guide to Constructing GUIs (2nd Edition)
ISBN: 0201914670
EAN: 2147483647
Year: 2004
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net