Using Components, the GUI Building Blocks |
[UNDER CONSTRUCTION]What else should this page cover? Send me suggestions!
Problem: My component never shows up!
Problem: My component isn't getting XYZ event!
- If you're not using the default layout manager, did you successfully create an instance of the right layout manager and call setLayoutManager() on the container?
- Did you add the component to its container using the right add() method for the container's layout manager? BorderLayout (the default layout manager for Panels), silently fails to add your component if you call the 1-argument version of add().
Problem: My application doesn't get a WINDOW_DESTROY event, so I can't close my window (or quit the application or whatever)!
- Check: Is the component is getting any events, at all. If not, make sure you're referring to the right component -- that you instantiated the right class, for example.
- If you're trying to catch a mouse event, make sure your component passes through mouse events. (Many don't.) Can you use another event type, such as ACTION_EVENT, instead?
- IN A FRAME SUBCLASS, implement handleEvent() so that it reacts to the the WINDOW_DESTROY event. Catching it in a Panel subclass, e.g., won't do, since the Frame is above it in the component hierarchy. To quit, use System.exit(). To destroy the window, you can implement dispose() or you can just hide() the Frame and make sure that all references to it are set to null.
Using Components, the GUI Building Blocks |