Java AWT

Previous Chapter 19
java.awt Reference
Next
 

Container

Name

Container

[Graphic: Figure from the text]

Description

The Container class serves as a general purpose holder of other Component objects.

Class Definition

public abstract class java.awt.Container
    extends java.awt.Component {
  // Constructors
  protected Container(); (New)
  
  // Instance Methods
  public Component add (Component component);
  public Component add (Component component, int position);
  public void add (Component comp, Object constraints); (New)
  public void add (Component comp, Object constraints, 
      int position); (New)
  public Component add (String name, Component component); (Deprecated)
  public void addContainerListener (ContainerListener l); (New)
  public void addNotify();
  public int countComponents();
  public void deliverEvent (Event e); (New)
  public void doLayout(); (New)
  public float getAlignmentX(); (New)
  public float getAlignmentY(); (New)
  public Component getComponent (int n);
  public Component getComponentAt (int x, int y);  (New)
  public Component getComponentAt (Point p);  (New)
  public int getComponentCount(); (New)
  public Component[] getComponents();
  public Insets getInsets(); (New)
  public LayoutManager getLayout();
  public Dimension getMaximumSize(); (New)
  public Dimension getMinimumSize();  (New)
  public Dimension getPreferredSize();  (New)
  public Insets insets();
  public void invalidate(); (New)
  public boolean isAncestorOf (Component c); (New)
  public void layout(); (Deprecated)
  public void list (PrintStream out, int indentation);
  public void list (PrintWriter out, int indentation); (New)
  public Component locate (int x, int y); (Deprecated)
  public Dimension minimumSize(); (Deprecated)
  public void paint (Graphics g); (New)
  public void paintComponents (Graphics g);
  public Dimension preferredSize(); (Deprecated)
  public void print (Graphics g); (New)
  public void printComponents (Graphics g);
  public void remove (int index); (New)
  public void remove (Component component);
  public void removeAll();
  public void removeContainerListener (ContainerListener l); (New)
  public void removeNotify();
  public void setLayout (LayoutManager manager);
  public void validate();
  // Protected Instance Methods
  protected void addImpl (Component comp, Object constraints, 
      int index); (New)
  protected String paramString();
  protected void processContainerEvent (ContainerEvent e); (New)
  protected void processEvent (AWTEvent e); (New)
  protected void validateTree(); (New)
}

Constructors

Container

protected Container() (New)

Description

This constructor creates a "lightweight" container. This constructor allows Container to be subclassed using code written entirely in Java.

Instance Methods

add

public Component add (Component component)

Parameters

component

Component to add to container.

Returns

Component just added.

Throws

IllegalArgumentException if you add component to itself.

Description

Adds component as the last component in the container.

public Component add (Component component, int position)

Parameters

component

Component to add to container.

position

Position of component; -1 adds the component as the last in the container.

Returns

Component just added.

Throws

ArrayIndexOutOfBoundsException

If position invalid.

IllegalArgumentException

If you add Component to itself.

Description

Adds component to container at a certain position.

public void add (Component component, Object constraints) (New)

Parameters

component

Component to add to container.

constraints

An object describing constraints on the component being added.

Description

Adds component to container subject to contraints.

public void add (Component component, Object constraints, int index) (New)

Parameters

component

Component to add to container.

constraints

An object describing constraints on the component being added.

index

The position of the component in the container's list.

Description

Adds component to container subject to contraints at position index.

public Component add (String name, Component component) (Deprecated)

Parameters

name

Name of component being added. This parameter is often significant to the layout manager of the container (e.g "North", "Center").

component

Component to add to container.

Returns

Component just added.

Throws

IllegalArgumentException

If you add component to itself.

Description

Adds the component to the container with the given name. Replaced by the more general add(Component, Object).

addContainerListener

public void addContainerListener (ContainerListener l) (New)

Parameters

l

An object that implements the ContainerListener interface.

Description

Add a listener for the container events.

addNotify

public void addNotify()

Overrides

Component.addNotify()

Description

Creates Container's peer and peers of contained components.

countComponents

public int countComponents()

Returns

Number of components within Container.

deliverEvent

public void deliverEvent (Event e) (Deprecated)

Parameters

e

Event instance to deliver.

Overrides

Component.deliverEvent(Event)

Description

Tries to locate the component contained in the container that should receive the event.

doLayout

public void doLayout() (New)

Description

Lays out the container. This method is a replacement for layout().

getAlignmentX

public float getAlignmentX() (New)

Returns

A number between 0 and 1 representing the horizontal alignment of this component.

Overrides

Component.getAlignmentX()

Description

If the container's layout manager implements LayoutManager2, this method returns the getLayoutAlignmentX() value of the layout manager. Otherwise the getAlignmentX() value of Component is returned.

getAlignmentY

public float getAlignmentY() (New)

Returns

A number between 0 and 1 representing the vertical alignment of this component.

Overrides

Component.getAlignmentY()

Description

If the container's layout manager implements LayoutManager2, this method returns the getLayoutAlignmentY() value of the layout manager. Otherwise the getAlignmentY() value of Component is returned.

getComponent

public synchronized Component getComponent (int position)

Parameters

position

Position of component to get.

Throws

ArrayIndexOutOfBoundsException

If position is invalid.

Returns

Component at designated position within Container.

getComponentAt

public Component getComponentAt (int x, int y) (New)

Parameters

x

The x coordinate, in this Container's coordinate system.

y

The y coordinate, in this Container's coordinate system.

Returns

Returns the Component containing the give point.

public Component getComponentAt (Point p) (New)

Parameters

p

The point to be tested, in this Container's coordinate system.

Returns

Returns the Component containing the give point.

getComponentCount

public int getComponentCount() (New)

Returns

Returns the number of components in the container.

getComponents

public Component[] getComponents()

Returns

Array of components within the container.

getInsets

public Insets getInsets()

Returns

The insets of the container.

getLayout

public LayoutManager getLayout()

Returns

LayoutManager of Container.

getMaximumSize

public Dimension getMaximumSize() (New)

Overrides

Component.getMaximumSize()

Returns

The maximum dimensions of the component.

getMinimumSize

public Dimension getMinimumSize() (New)

Overrides

Component.getMinimumSize()

Returns

The minimum dimensions of the component.

getPreferredSize

public Dimension getPreferredSize() (New)

Returns

The preferred dimensions of the component.

insets

public Insets insets() (Deprecated)

Returns

Current Insets of Container. Replaced by getInsets().

invalidate

public void invalidate()

Overrides

Component.invalidate()

Description

Sets the container's valid state to false.

isAncestorOf

public boolean isAncestorOf (Component c) (New)

Parameters

c

The component in question.

Returns

If c is contained in the container's hierarchy, returns true; otherwise false.

layout

public void layout() (Deprecated)

Overrides

Component.layout()

Description

Replaced by doLayout().

list

public void list (PrintStream out, int indentation)

Parameters

out

Output Stream to send results to.

indentation

Indentation to use when printing.

Overrides

Component.list(PrintStream, int)

Description

Recursively lists all components in Container.

public void list (PrintWriter out, int indentation)

Parameters

out

Output Writer to send results to.

indentation

Indentation to use when printing.

Overrides

Component.list(PrintWriter, int)

Description

Recursively lists all components in Container.

locate

public Component locate (int x, int y) (Deprecated)

Parameters

x

Horizontal position to check.

y

Vertical position to check.

Returns

Component within Container at given coordinates, or Container.

Overrides

Component.locate(int, int)

Description

Replaced by getComponentAt(int, int).

minimizeSize

public Dimension minimumSize() (Deprecated)

Returns

Minimum dimensions of contained objects.

Overrides

Component.minimumSize()

Description

Replaced by getMinimumSize().

paint

public void paint (Graphics g)

Parameters

g

Graphics context of container.

Overrides

Component.paint()

Description

This method tells any lightweight components that are children of this container to paint themselves.

paintComponents

public void paintComponents (Graphics g)

Parameters

g

Graphics context of Container.

Description

Paints the different components in Container.

preferredSize

public Dimension preferredSize() (Deprecated)

Returns

Preferred dimensions of contained objects.

Overrides

Component.preferredSize()

Description

Replaced by getPreferredSize().

print

public void print (Graphics g)

Parameters

g

Graphics context of container.

Overrides

Component.print()

Description

This method tells any lightweight components that are children of this container to print themselves.

printComponents

public void printComponents (Graphics g)

Parameters

g

Graphics context of Container.

Description

Prints the different components in Container.

remove

public void remove (int index) (New)

Parameters

index

Index of the component to remove.

Description

Removes the component in position index from Container.

public void remove (Component component)

Parameters

component

Component to remove.

Description

Removes component from Container.

removeAll

public void removeAll()

Description

Removes all components from Container.

removeContainerListener

public void removeContainerListener (ContainerListener l) (New)

Parameters

l

One of this Container's ContainerListeners.

Description

Remove a container event listener.

removeNotify

public void removeNotify()

Overrides

Component.removeNotify()

Description

Removes Container's peer and peers of contained components.

setLayout

public void setLayout (LayoutManager manager)

Parameters

manager

New LayoutManager for Container.

Description

Changes LayoutManager of Container.

validate

public void validate()

Overrides

Component.validate()

Description

Sets Container's valid state to true and recursively validates its children.

Protected Instance Methods

addImpl

protected void addImpl (Component comp, Object constraints, int index) (New)

Parameters

comp

The component to add.

constraints

Constraints on the component.

index

Position at which to add this component. Pass -1 to add the component at the end.

Description

This method adds a component subject to the given constraints at a specific position in the container's list of components. It is a helper method for the various overrides of add().

paramString

protected String paramString()

Returns

String with current settings of Container.

Overrides

Component.paramString()

Description

Helper method for toString() to generate string of current settings.

processContainerEvent

protected void processContainerEvent (ContainerEvent e) (New)

Parameters

e

The event to process.

Description

Container events are passed to this method for processing. Normally, this method is called by processEvent().

processEvent

protected void processEvent (AWTEvent e) (New)

Parameters

e

The event to process.

Overrides

Component.processEvent()

Description

Low level AWTEvents are passed to this method for processing.

validateTree

protected void validateTree() (New)

Description

Descends recursively into the Container's components and recalculates layout for any subtrees that are marked invalid.

See Also

Component, Dimension, Event, Graphics, Insets, LayoutManager, Panel, PrintStream, String, Window


Previous Home Next
Component Book Index Cursor (New)

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java