java.awt.event

Class ComponentEvent

Implemented Interfaces:
Serializable
Known Direct Subclasses:
ContainerEvent, FocusEvent, InputEvent, PaintEvent, WindowEvent

public class ComponentEvent
extends AWTEvent

A low-level event which indicates that a component moved, changed size, or changed visibility (also, the root class for the other component-level events).

Component events are provided for notification purposes ONLY; The AWT will automatically handle component moves and resizes internally so that GUI layout works properly regardless of whether a program is receiving these events or not.

In addition to serving as the base class for other component-related events (InputEvent, FocusEvent, WindowEvent, ContainerEvent), this class defines the events that indicate changes in a component's size, position, or visibility.

This low-level event is generated by a component object (such as a List) when the component is moved, resized, rendered invisible, or made visible again. The event is passed to every ComponentListener or ComponentAdapter object which registered to receive such events using the component's addComponentListener method. (ComponentAdapter objects implement the ComponentListener interface.) Each such listener object gets this ComponentEvent when the event occurs.

Since:
1.1
See Also:
ComponentAdapter, ComponentListener, Tutorial: Writing a Component Listener, Reference: The Java Class Libraries (update file), Serialized Form

Field Summary

static int
COMPONENT_FIRST
The first number in the range of ids used for component events.
static int
COMPONENT_HIDDEN
This event indicates that the component was rendered invisible.
static int
COMPONENT_LAST
The last number in the range of ids used for component events.
static int
COMPONENT_MOVED
This event indicates that the component's position changed.
static int
COMPONENT_RESIZED
This event indicates that the component's size changed.
static int
COMPONENT_SHOWN
This event indicates that the component was made visible.

Fields inherited from class java.awt.AWTEvent

ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK, consumed, id

Fields inherited from class java.util.EventObject

source

Constructor Summary

ComponentEvent(Component source, int id)
Constructs a ComponentEvent object.

Method Summary

Component
getComponent()
Returns the originator of the event.
String
paramString()
Returns a parameter string identifying this event.

Methods inherited from class java.awt.AWTEvent

consume, getID, isConsumed, paramString, setSource, toString

Methods inherited from class java.util.EventObject

getSource, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

COMPONENT_FIRST

public static final int COMPONENT_FIRST
The first number in the range of ids used for component events.
Field Value:
100

COMPONENT_HIDDEN

public static final int COMPONENT_HIDDEN
This event indicates that the component was rendered invisible.
Field Value:
103
Usages and Demos :

View More Examples of ComponentEvent.COMPONENT_HIDDEN
   1:         switch (id) {
   2:         case ComponentEvent.COMPONENT_HIDDEN:
   3:             dispose();
   4:             currentClientComponent = null;
   5:             break;

View Full Code Here
   1:         break;
   2:       case ComponentEvent.COMPONENT_HIDDEN:
   3:         display.evnt[Display.COMPONENT] = 
   4:           "Component hidden";
   5:         break;

View Full Code Here
   1:     ComponentEvent e = new ComponentEvent(owner, 
   2:                       ComponentEvent.COMPONENT_HIDDEN);
   3:     QtToolkit.eventQueue.postEvent(e);
   4:   }

View Full Code Here
   1:          show = new WakeupOnAWTEvent(ComponentEvent.COMPONENT_SHOWN);
   2:          hide = new WakeupOnAWTEvent(ComponentEvent.COMPONENT_HIDDEN);
   3:          cond = new WakeupOr(new WakeupCriterion[] {show, hide});
   4:       }

View Full Code Here
   1:         ComponentEvent ce =
   2:           new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
   3:         getToolkit().getSystemEventQueue().postEvent(ce);
   4:         ...
   5:       {
   6:       case ComponentEvent.COMPONENT_HIDDEN:
   7:         componentListener.componentHidden(e);
   8:         ...
   9:       {
  10:       case ComponentEvent.COMPONENT_HIDDEN:
  11:       case ComponentEvent.COMPONENT_MOVED:

View Full Code Here

COMPONENT_LAST

public static final int COMPONENT_LAST
The last number in the range of ids used for component events.
Field Value:
103
Usages and Demos :

View More Examples of ComponentEvent.COMPONENT_LAST
   1:     public static int COMPONENT_TRANSFORM_CHANGED =
   2:         ComponentEvent.COMPONENT_LAST+1234;
   3:     public void componentTransformChanged
   4:         (ComponentEvent event);
   5: }

View Full Code Here

COMPONENT_MOVED

public static final int COMPONENT_MOVED
This event indicates that the component's position changed.
Field Value:
100
Usages and Demos :

View More Examples of ComponentEvent.COMPONENT_MOVED
   1:     switch(e.getID()) {
   2:       case ComponentEvent.COMPONENT_MOVED:
   3:         display.evnt[Display.COMPONENT] = 
   4:           "Component moved";
   5:         break;

View Full Code Here
   1:         ComponentEvent ce =
   2:           new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED);
   3:         getToolkit().getSystemEventQueue().postEvent(ce);
   4:       }
   5:   }

View Full Code Here
   1:         ComponentEvent ce = new ComponentEvent(this,
   2:                                                ComponentEvent.COMPONENT_MOVED);
   3:         getToolkit().getSystemEventQueue().postEvent(ce);
   4:         ...
   5:         break;
   6:       case ComponentEvent.COMPONENT_MOVED:
   7:         componentListener.componentMoved(e);
   8:         ...
   9:       case ComponentEvent.COMPONENT_HIDDEN:
  10:       case ComponentEvent.COMPONENT_MOVED:
  11:       case ComponentEvent.COMPONENT_RESIZED:

View Full Code Here

COMPONENT_RESIZED

public static final int COMPONENT_RESIZED
This event indicates that the component's size changed.
Field Value:
101
Usages and Demos :

View More Examples of ComponentEvent.COMPONENT_RESIZED
   1:         {
   2:         case ComponentEvent.COMPONENT_RESIZED:
   3:             reconfigure();
   4:             break;
   5:         }

View Full Code Here
   1: 
   2:         case ComponentEvent.COMPONENT_RESIZED:
   3:         {
   4:           ComponentEvent ce = (ComponentEvent)event;
   5:           ce.getComponent ().validate ();

View Full Code Here
   1:         break;
   2:       case ComponentEvent.COMPONENT_RESIZED:
   3:         display.evnt[Display.COMPONENT] = 
   4:           "Component resized";
   5:         break;

View Full Code Here
   1:     ComponentEvent e = new ComponentEvent(owner, 
   2:                         ComponentEvent.COMPONENT_RESIZED);
   3:     QtToolkit.eventQueue.postEvent(e);
   4:     QtToolkit.repaintThread.queueComponent(this);
   5:   }

View Full Code Here
   1:         dispatchEvent(new ComponentEvent(frame,
   2:             ComponentEvent.COMPONENT_RESIZED));
   3:       } else if (dialog != null) {
   4:       }
   5:     }

View Full Code Here

COMPONENT_SHOWN

public static final int COMPONENT_SHOWN
This event indicates that the component was made visible.
Field Value:
102
Usages and Demos :

View More Examples of ComponentEvent.COMPONENT_SHOWN
   1: 
   2:         case ComponentEvent.COMPONENT_SHOWN:
   3:         {
   4:           ComponentEvent ce = (ComponentEvent)event;
   5:           Component comp = ce.getComponent ();

View Full Code Here
   1:         break;
   2:       case ComponentEvent.COMPONENT_SHOWN:
   3:         display.evnt[Display.COMPONENT] = 
   4:           "Component shown";
   5:         break;

View Full Code Here
   1:     ComponentEvent e = new ComponentEvent(owner, 
   2:                           ComponentEvent.COMPONENT_SHOWN);
   3:     QtToolkit.eventQueue.postEvent(e);
   4:       }
   5:   }

View Full Code Here
   1:       {
   2:          show = new WakeupOnAWTEvent(ComponentEvent.COMPONENT_SHOWN);
   3:          hide = new WakeupOnAWTEvent(ComponentEvent.COMPONENT_HIDDEN);
   4:          cond = new WakeupOr(new WakeupCriterion[] {show, hide});
   5:       }

View Full Code Here
   1:         ComponentEvent ce =
   2:           new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
   3:         getToolkit().getSystemEventQueue().postEvent(ce);
   4:         ...
   5:         break;
   6:       case ComponentEvent.COMPONENT_SHOWN:
   7:         componentListener.componentShown(e);
   8:         ...
   9:       case ComponentEvent.COMPONENT_RESIZED:
  10:       case ComponentEvent.COMPONENT_SHOWN:
  11:         return (componentListener != null

View Full Code Here

Constructor Details

ComponentEvent

public ComponentEvent(Component source,
                      int id)
Constructs a ComponentEvent object.

Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.

Parameters:
source - the Component that originated the event
id - an integer indicating the type of event
Throws:
IllegalArgumentException - if source is null
Usages and Demos :

View More Examples of ComponentEvent(Component source,int id)
   1:     {
   2:         this.setReusableEvent(new ComponentEvent(source, 0));
   3:         componentResizeObserver = new ComponentAdapter()
   4:         {
   5:             public void componentResized (ComponentEvent e)

View Full Code Here
   1:         {
   2:             resizedMulticaster.setReusableEvent(new ComponentEvent(delegator, 0));
   3:         }
   4:         resizedMulticaster.fireReusableEvent();
   5:     }

View Full Code Here
   1:     if(evt instanceof ComponentEvent)
   2:         return new ComponentEvent(src, evt.getID());
   3:                 
   4:     return null;
   5:     }

View Full Code Here
   1:         {
   2:             resizedMulticaster.setReusableEvent(new ComponentEvent(delegator, 0));
   3:         }
   4:         resizedMulticaster.fireReusableEvent();
   5:     }

View Full Code Here
   1:         if(evt instanceof ComponentEvent)
   2:             return new ComponentEvent(src, evt.getID());
   3: 
   4:         return null;
   5:     }

View Full Code Here

Method Details

getComponent

public Component getComponent()
Returns the originator of the event.
Returns:
the Component object that originated the event, or null if the object is not a Component.
Usages and Demos :

View More Examples of getComponent()
   1:         try {
   2:             ComponentEvent ce = (ComponentEvent)evt;
   3:             this.put(
   4:         ...
   5:                 ce.getComponent().getName(),
   6:         ...
   7:                 ce.getComponent()
   8:                 );

View Full Code Here
   1:     @Override
   2:     public void componentResized( ComponentEvent event )
   3:     {
   4:         ...
   5:       if ( event.getID() == ComponentEvent.COMPONENT_RESIZED )
   6:       {
   7:         ...
   8:         JFrame f = (JFrame) event.getComponent();

View Full Code Here
   1:     
   2:     public void componentMoved(ComponentEvent evt) {
   3:         if(locked) return;
   4:         ...
   5:         Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
   6:         int nx = evt.getComponent().getX();
   7:         ...
   8:         int ny = evt.getComponent().getY();
   9:         if(ny < 0+sd) {
  10:         ...
  11:         }
  12:         if(nx > size.getWidth()-evt.getComponent().getWidth()-sd) {

View Full Code Here
   1: import java.awt.Component;
   2: import java.awt.event.ComponentEvent;
   3: 
   4:         ...
   5: 
   6:     private void call(String s, ComponentEvent componentevent) {
   7:         ...
   8:         JHandler.callLisp(s, componentevent.getComponent(), componentevent.paramString());
   9:     }

View Full Code Here
   1: import java.awt.EventQueue;
   2: import java.awt.event.ComponentEvent;
   3: import java.awt.event.ContainerEvent;
   4:         ...
   5: 
   6:         case ComponentEvent.COMPONENT_RESIZED:
   7:         {
   8:         ...
   9:           ComponentEvent ce = (ComponentEvent)event;
  10:         ...
  11:           ce.getComponent().validate ();

View Full Code Here

paramString

public String paramString()
Returns a parameter string identifying this event. This method is useful for event-logging and for debugging.
Overrides:
paramString in interface AWTEvent
Returns:
a string identifying the event and its attributes
Usages and Demos :

View More Examples of paramString()
   1: import java.awt.Component;
   2: import java.awt.event.ComponentEvent;
   3: 
   4:         ...
   5: 
   6:     private void call(String s, ComponentEvent componentevent) {
   7:         ...
   8:         JHandler.callLisp(s, componentevent.getComponent(), componentevent.paramString());
   9:     }

View Full Code Here