17.4. Basics of Components
You need to understand several basic concepts common to all components before you can apply them properly. They also have applications in many different contexts. While this may seem like something of a catalog of classes and methods, without much in the way of practical application, please stay with it. You'll be using most of these capabilities in a practical context later. To understand the fundamental things you can do with Swing components, you'll be examining what functionality the Swing components inherit from the Component and Container classes.
When a component is contained within another component, the outer object is referred to as the parent. You can obtain a reference to the parent object of any given component by calling its getParent() method. This method is inherited from the Component class, and it returns the parent as type Container, since only a subclass of Container can hold other components. If there is no parent, as is the case with a JFrame component, this method will return null.
17.4.1. Component Attributes
The Component class defines attributes, which record the following information about an object:
The position is stored as (x, y) coordinates. This fixes where the object is in relation to its container in the coordinate system of the container object.
The name of the component is stored as a String object.
The size is recorded as values for the width and the height of the object.
The foreground color and background color that ...
Get Ivor Horton's Beginning Java™ 2, JDK™ 5th 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.