| Method from java.awt.Component Detail: |
public boolean action(Event evt,
Object what) {
return false;
} Deprecated! in - classes which support actions, use
processActionEvent(ActionEvent) instead
AWT 1.0 ACTION_EVENT event handler. This method is meant to be
overridden by components providing their own action event
handler. The default implementation simply returns false. |
public synchronized void add(PopupMenu popup) {
if (popups == null)
popups = new Vector();
popups.add(popup);
if (popup.parent != null)
popup.parent.remove(popup);
popup.parent = this;
if (peer != null)
popup.addNotify();
}
Adds the specified popup menu to this component. |
public synchronized void addComponentListener(ComponentListener listener) {
componentListener = AWTEventMulticaster.add(componentListener, listener);
if (componentListener != null)
enableEvents(AWTEvent.COMPONENT_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public synchronized void addFocusListener(FocusListener listener) {
focusListener = AWTEventMulticaster.add(focusListener, listener);
if (focusListener != null)
enableEvents(AWTEvent.FOCUS_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public synchronized void addHierarchyBoundsListener(HierarchyBoundsListener listener) {
hierarchyBoundsListener =
AWTEventMulticaster.add(hierarchyBoundsListener, listener);
if (hierarchyBoundsListener != null)
enableEvents(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public synchronized void addHierarchyListener(HierarchyListener listener) {
hierarchyListener = AWTEventMulticaster.add(hierarchyListener, listener);
if (hierarchyListener != null)
enableEvents(AWTEvent.HIERARCHY_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public synchronized void addInputMethodListener(InputMethodListener listener) {
inputMethodListener = AWTEventMulticaster.add(inputMethodListener, listener);
if (inputMethodListener != null)
enableEvents(AWTEvent.INPUT_METHOD_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public synchronized void addKeyListener(KeyListener listener) {
keyListener = AWTEventMulticaster.add(keyListener, listener);
if (keyListener != null)
enableEvents(AWTEvent.KEY_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public synchronized void addMouseListener(MouseListener listener) {
mouseListener = AWTEventMulticaster.add(mouseListener, listener);
if (mouseListener != null)
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public synchronized void addMouseMotionListener(MouseMotionListener listener) {
mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, listener);
if (mouseMotionListener != null)
enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public synchronized void addMouseWheelListener(MouseWheelListener listener) {
mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener, listener);
if (mouseWheelListener != null)
enableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
}
Adds the specified listener to this component. This is harmless if the
listener is null, but if the listener has already been registered, it
will now be registered twice. |
public void addNotify() {
if (peer == null)
peer = getToolkit().createComponent(this);
else if (parent != null && parent.isLightweight())
new HeavyweightInLightweightListener(parent);
/* Now that all the children has gotten their peers, we should
have the event mask needed for this component and its
lightweight subcomponents. */
peer.setEventMask(eventMask);
/* We do not invalidate here, but rather leave that job up to
the peer. For efficiency, the peer can choose not to
invalidate if it is happy with the current dimensions,
etc. */
}
Called when the parent of this Component is made visible or when
the Component is added to an already visible Container and needs
to be shown. A native peer - if any - is created at this
time. This method is called automatically by the AWT system and
should not be called by user level code. |
public void addPropertyChangeListener(PropertyChangeListener listener) {
if (changeSupport == null)
changeSupport = new PropertyChangeSupport(this);
changeSupport.addPropertyChangeListener(listener);
}
Adds the specified property listener to this component. This is harmless
if the listener is null, but if the listener has already been registered,
it will now be registered twice. The property listener ignores inherited
properties. Recognized properties include:
- the font (
"font")
- the background color (
"background")
- the foreground color (
"foreground")
- the focusability (
"focusable")
- the focus key traversal enabled state
(
"focusTraversalKeysEnabled")
- the set of forward traversal keys
(
"forwardFocusTraversalKeys")
- the set of backward traversal keys
(
"backwardFocusTraversalKeys")
- the set of up-cycle traversal keys
(
"upCycleFocusTraversalKeys")
|
public void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener) {
if (changeSupport == null)
changeSupport = new PropertyChangeSupport(this);
changeSupport.addPropertyChangeListener(propertyName, listener);
}
Adds the specified property listener to this component. This is harmless
if the listener is null, but if the listener has already been registered,
it will now be registered twice. The property listener ignores inherited
properties. The listener is keyed to a single property. Recognized
properties include:
- the font (
"font")
- the background color (
"background")
- the foreground color (
"foreground")
- the focusability (
"focusable")
- the focus key traversal enabled state
(
"focusTraversalKeysEnabled")
- the set of forward traversal keys
(
"forwardFocusTraversalKeys")
p * - the set of backward traversal keys
(
"backwardFocusTraversalKeys")
- the set of up-cycle traversal keys
(
"upCycleFocusTraversalKeys")
|
public void applyComponentOrientation(ComponentOrientation o) {
setComponentOrientation(o);
}
Sets the text layout orientation of this component. New components default
to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects the
entire hierarchy, while
#setComponentOrientation(ComponentOrientation) affects only the
current component. |
public boolean areFocusTraversalKeysSet(int id) {
if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS)
throw new IllegalArgumentException ();
return focusTraversalKeys != null && focusTraversalKeys[id] != null;
}
Tests whether the focus traversal keys for a given action are explicitly
set or inherited. |
public Rectangle bounds() {
return new Rectangle (x, y, width, height);
} Deprecated! use - #getBounds() instead
Returns a bounding rectangle for this component. Note that the
returned rectange is relative to this component's parent, not to
the screen. |
public int checkImage(Image image,
ImageObserver observer) {
return checkImage(image, -1, -1, observer);
}
Returns the status of the loading of the specified image. The value
returned will be those flags defined in ImageObserver. |
public int checkImage(Image image,
int width,
int height,
ImageObserver observer) {
if (peer != null)
return peer.checkImage(image, width, height, observer);
return getToolkit().checkImage(image, width, height, observer);
}
Returns the status of the loading of the specified image. The value
returned will be those flags defined in ImageObserver. |
protected AWTEvent coalesceEvents(AWTEvent existingEvent,
AWTEvent newEvent) {
switch (existingEvent.id)
{
case MouseEvent.MOUSE_MOVED:
case MouseEvent.MOUSE_DRAGGED:
// Just drop the old (intermediate) event and return the new one.
return newEvent;
case PaintEvent.PAINT:
case PaintEvent.UPDATE:
return coalescePaintEvents((PaintEvent) existingEvent,
(PaintEvent) newEvent);
default:
return null;
}
}
This is called by the EventQueue if two events with the same event id
and owner component are queued. Returns a new combined event, or null if
no combining is done. The coelesced events are currently mouse moves
(intermediate ones are discarded) and paint events (a merged paint is
created in place of the two events). |
public boolean contains(Point p) {
return contains (p.x, p.y);
}
Tests whether or not the specified point is contained within this
component. Coordinates are relative to this component. |
public boolean contains(int x,
int y) {
return inside (x, y);
}
Tests whether or not the specified point is contained within this
component. Coordinates are relative to this component. |
public Image createImage(ImageProducer producer) {
// Sun allows producer to be null.
if (peer != null)
return peer.createImage(producer);
else
return getToolkit().createImage(producer);
}
Creates an image from the specified producer. |
public Image createImage(int width,
int height) {
Image returnValue = null;
if (!GraphicsEnvironment.isHeadless ())
{
if (isLightweight () && parent != null)
returnValue = parent.createImage (width, height);
else if (peer != null)
returnValue = peer.createImage (width, height);
}
return returnValue;
}
Creates an image with the specified width and height for use in
double buffering. Headless environments do not support images. |
public VolatileImage createVolatileImage(int width,
int height) {
if (GraphicsEnvironment.isHeadless())
return null;
GraphicsConfiguration config = getGraphicsConfiguration();
return config == null ? null
: config.createCompatibleVolatileImage(width, height);
}
Creates an image with the specified width and height for use in
double buffering. Headless environments do not support images. |
public VolatileImage createVolatileImage(int width,
int height,
ImageCapabilities caps) throws AWTException {
if (GraphicsEnvironment.isHeadless())
return null;
GraphicsConfiguration config = getGraphicsConfiguration();
return config == null ? null
: config.createCompatibleVolatileImage(width, height, caps);
}
Creates an image with the specified width and height for use in
double buffering. Headless environments do not support images. The image
will support the specified capabilities. |
public void deliverEvent(Event e) {
postEvent (e);
} Deprecated! use - (AWTEvent) instead
AWT 1.0 event delivery.
Deliver an AWT 1.0 event to this Component. This method simply
calls #postEvent . |
public void disable() {
this.enabled = false;
if (peer != null)
peer.setEnabled (false);
} Deprecated! use - #setEnabled(boolean) instead
|
protected final void disableEvents(long eventsToDisable) {
eventMask &= ~eventsToDisable;
// forward new event mask to peer?
}
Disables the specified events. The events to disable are specified
by OR-ing together the desired masks from AWTEvent. |
public final void dispatchEvent(AWTEvent e) {
Event oldEvent = translateEvent(e);
if (oldEvent != null)
postEvent (oldEvent);
// Give toolkit a chance to dispatch the event
// to globally registered listeners.
Toolkit.getDefaultToolkit().globalDispatchEvent(e);
// Some subclasses in the AWT package need to override this behavior,
// hence the use of dispatchEventImpl().
dispatchEventImpl(e);
}
Forwards AWT events to processEvent() if:
- Events have been enabled for this type of event via
enableEvents() ,
- There is at least one registered listener for this type of event
|
void dispatchEventImpl(AWTEvent e) {
// This boolean tells us not to process focus events when the focus
// opposite component is the same as the focus component.
boolean ignoreFocus =
(e instanceof FocusEvent &&
((FocusEvent)e).getComponent() == ((FocusEvent)e).getOppositeComponent());
if (eventTypeEnabled (e.id))
{
if (e.id != PaintEvent.PAINT && e.id != PaintEvent.UPDATE
&& !ignoreFocus)
processEvent(e);
// the trick we use to communicate between dispatch and redispatch
// is to have KeyboardFocusManager.redispatch synchronize on the
// object itself. we then do not redispatch to KeyboardFocusManager
// if we are already holding the lock.
if (! Thread.holdsLock(e))
{
switch (e.id)
{
case WindowEvent.WINDOW_GAINED_FOCUS:
case WindowEvent.WINDOW_LOST_FOCUS:
case KeyEvent.KEY_PRESSED:
case KeyEvent.KEY_RELEASED:
case KeyEvent.KEY_TYPED:
case FocusEvent.FOCUS_GAINED:
case FocusEvent.FOCUS_LOST:
if (KeyboardFocusManager
.getCurrentKeyboardFocusManager()
.dispatchEvent(e))
return;
case MouseEvent.MOUSE_PRESSED:
if (isLightweight() && !e.isConsumed())
requestFocus();
break;
}
}
}
if (peer != null)
peer.handleEvent(e);
}
Implementation of dispatchEvent. Allows trusted package classes
to dispatch additional events first. This implementation first
translates e to an AWT 1.0 event and sends the
result to #postEvent . If the AWT 1.0 event is not
handled, and events of type e are enabled for this
component, e is passed on to #processEvent . |
public void doLayout() {
layout ();
}
Calls the layout manager to re-layout the component. This is called
during validation of a container in most cases. |
public void enable() {
this.enabled = true;
if (peer != null)
peer.setEnabled (true);
} Deprecated! use - #setEnabled(boolean) instead
|
public void enable(boolean enabled) {
if (enabled)
enable();
else
disable();
} Deprecated! use - #setEnabled(boolean) instead
Enables or disables this component. |
protected final void enableEvents(long eventsToEnable) {
eventMask |= eventsToEnable;
// TODO: Unlike Sun's implementation, I think we should try and
// enable/disable events at the peer (gtk/X) level. This will avoid
// clogging the event pipeline with useless mousemove events that
// we arn't interested in, etc. This will involve extending the peer
// interface, but thats okay because the peer interfaces have been
// deprecated for a long time, and no longer feature in the
// API specification at all.
if (isLightweight() && parent != null)
parent.enableEvents(eventsToEnable);
else if (peer != null)
peer.setEventMask(eventMask);
}
Enables the specified events. The events to enable are specified
by OR-ing together the desired masks from AWTEvent.
Events are enabled by default when a listener is attached to the
component for that event type. This method can be used by subclasses
to ensure the delivery of a specified event regardless of whether
or not a listener is attached. |
public void enableInputMethods(boolean enable) {
if (enable)
eventMask |= AWTEvent.INPUT_ENABLED_EVENT_MASK;
else
eventMask &= ~AWTEvent.INPUT_ENABLED_EVENT_MASK;
}
Enables or disables input method support for this component. By default,
components have this enabled. Input methods are given the opportunity
to process key events before this component and its listeners. |
boolean eventTypeEnabled(int type) {
if (type > AWTEvent.RESERVED_ID_MAX)
return true;
switch (type)
{
case HierarchyEvent.HIERARCHY_CHANGED:
return (hierarchyListener != null
|| (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0);
case HierarchyEvent.ANCESTOR_MOVED:
case HierarchyEvent.ANCESTOR_RESIZED:
return (hierarchyBoundsListener != null
|| (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0);
case ComponentEvent.COMPONENT_HIDDEN:
case ComponentEvent.COMPONENT_MOVED:
case ComponentEvent.COMPONENT_RESIZED:
case ComponentEvent.COMPONENT_SHOWN:
return (componentListener != null
|| (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0);
case KeyEvent.KEY_PRESSED:
case KeyEvent.KEY_RELEASED:
case KeyEvent.KEY_TYPED:
return (keyListener != null
|| (eventMask & AWTEvent.KEY_EVENT_MASK) != 0);
case MouseEvent.MOUSE_CLICKED:
case MouseEvent.MOUSE_ENTERED:
case MouseEvent.MOUSE_EXITED:
case MouseEvent.MOUSE_PRESSED:
case MouseEvent.MOUSE_RELEASED:
return (mouseListener != null
|| (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0);
case MouseEvent.MOUSE_MOVED:
case MouseEvent.MOUSE_DRAGGED:
return (mouseMotionListener != null
|| (eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0);
case MouseEvent.MOUSE_WHEEL:
return (mouseWheelListener != null
|| (eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0);
case FocusEvent.FOCUS_GAINED:
case FocusEvent.FOCUS_LOST:
return (focusListener != null
|| (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0);
case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
case InputMethodEvent.CARET_POSITION_CHANGED:
return (inputMethodListener != null
|| (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0);
case PaintEvent.PAINT:
case PaintEvent.UPDATE:
return (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0;
default:
return false;
}
}
Tells whether or not an event type is enabled. |
Component findNextFocusComponent(Component child) {
return null;
}
This method is used to implement transferFocus(). CHILD is the child
making the request. This is overridden by Container; when called for an
ordinary component there is no child and so we always return null.
FIXME: is this still needed, in light of focus traversal policies? |
protected void firePropertyChange(String propertyName,
Object oldValue,
Object newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
Report a change in a bound property to any registered property listeners. |
protected void firePropertyChange(String propertyName,
boolean oldValue,
boolean newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
Report a change in a bound property to any registered property listeners. |
protected void firePropertyChange(String propertyName,
int oldValue,
int newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
Report a change in a bound property to any registered property listeners. |
public void firePropertyChange(String propertyName,
byte oldValue,
byte newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, new Byte(oldValue),
new Byte(newValue));
}
Report a change in a bound property to any registered property listeners. |
public void firePropertyChange(String propertyName,
char oldValue,
char newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, new Character(oldValue),
new Character(newValue));
}
Report a change in a bound property to any registered property listeners. |
public void firePropertyChange(String propertyName,
short oldValue,
short newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, new Short(oldValue),
new Short(newValue));
}
Report a change in a bound property to any registered property listeners. |
public void firePropertyChange(String propertyName,
long oldValue,
long newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, new Long(oldValue),
new Long(newValue));
}
Report a change in a bound property to any registered property listeners. |
public void firePropertyChange(String propertyName,
float oldValue,
float newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, new Float(oldValue),
new Float(newValue));
}
Report a change in a bound property to any registered property listeners. |
public void firePropertyChange(String propertyName,
double oldValue,
double newValue) {
if (changeSupport != null)
changeSupport.firePropertyChange(propertyName, new Double(oldValue),
new Double(newValue));
}
Report a change in a bound property to any registered property listeners. |
String generateName() {
// Component is abstract.
return null;
}
Subclasses should override this to return unique component names like
"menuitem0". |
public AccessibleContext getAccessibleContext() {
return null;
}
Returns the accessibility framework context of this class. Component is
not accessible, so the default implementation returns null. Subclasses
must override this behavior, and return an appropriate subclass of
AccessibleAWTComponent . |
public float getAlignmentX() {
return CENTER_ALIGNMENT;
}
|
public float getAlignmentY() {
return CENTER_ALIGNMENT;
}
|
public Color getBackground() {
if (background != null)
return background;
return parent == null ? null : parent.getBackground();
}
Returns this component's background color. If not set, this is inherited
from the parent. |
public Rectangle getBounds() {
return bounds ();
}
Returns a bounding rectangle for this component. Note that the
returned rectange is relative to this component's parent, not to
the screen. |
public Rectangle getBounds(Rectangle r) {
if (r == null)
r = new Rectangle();
r.x = x;
r.y = y;
r.width = width;
r.height = height;
return r;
}
Returns the bounds of this component. This allows reuse of an existing
rectangle, if r is non-null. |
public ColorModel getColorModel() {
GraphicsConfiguration config = getGraphicsConfiguration();
return config != null ? config.getColorModel()
: getToolkit().getColorModel();
}
Returns the color model of the device this componet is displayed on. |
public Component getComponentAt(Point p) {
return getComponentAt (p.x, p.y);
}
Returns the component occupying the position (x,y). This will either
be this component, an immediate child component, or null
if neither of the first two occupies the specified location. |
public Component getComponentAt(int x,
int y) {
return locate (x, y);
}
Returns the component occupying the position (x,y). This will either
be this component, an immediate child component, or null
if neither of the first two occupies the specified location. |
public synchronized ComponentListener[] getComponentListeners() {
return (ComponentListener[])
AWTEventMulticaster.getListeners(componentListener,
ComponentListener.class);
}
Returns an array of all specified listeners registered on this component. |
public ComponentOrientation getComponentOrientation() {
return orientation;
}
Determines the text layout orientation used by this component. |
public Cursor getCursor() {
if (cursor != null)
return cursor;
return parent != null ? parent.getCursor() : Cursor.getDefaultCursor();
}
Returns the cursor for this component. If not set, this is inherited
from the parent, or from Cursor.getDefaultCursor(). |
public DropTarget getDropTarget() {
return dropTarget;
}
Gets the associated drag-and-drop target, if there is one. |
public Container getFocusCycleRootAncestor() {
Container parent = getParent ();
while (parent != null && !parent.isFocusCycleRoot())
parent = parent.getParent ();
return parent;
}
Returns the root container that owns the focus cycle where this
component resides. A focus cycle root is in two cycles, one as
the ancestor, and one as the focusable element; this call always
returns the ancestor. |
public synchronized FocusListener[] getFocusListeners() {
return (FocusListener[])
AWTEventMulticaster.getListeners(focusListener, FocusListener.class);
}
Returns an array of all specified listeners registered on this component. |
public Set getFocusTraversalKeys(int id) {
if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&
id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS)
throw new IllegalArgumentException();
Set s = null;
if (focusTraversalKeys != null)
s = focusTraversalKeys[id];
if (s == null && parent != null)
s = parent.getFocusTraversalKeys (id);
return s == null ? (KeyboardFocusManager.getCurrentKeyboardFocusManager()
.getDefaultFocusTraversalKeys(id)) : s;
}
Returns the set of keys for a given focus traversal action, as
defined in setFocusTraversalKeys. If not set, this
is inherited from the parent component, which may have gotten it
from the KeyboardFocusManager. |
public boolean getFocusTraversalKeysEnabled() {
return focusTraversalKeysEnabled;
}
Check whether or not focus traversal keys are enabled on this
Component. If they are, then the keyboard focus manager consumes
and acts on key press and release events that trigger focus
traversal, and discards the corresponding key typed events. If
focus traversal keys are disabled, then all key events that would
otherwise trigger focus traversal are sent to this Component. |
public Font getFont() {
Font f = font;
if (f != null)
return f;
Component p = parent;
if (p != null)
return p.getFont();
return null;
}
Returns the font in use for this component. If not set, this is inherited
from the parent. |
public FontMetrics getFontMetrics(Font font) {
return peer == null ? getToolkit().getFontMetrics(font)
: peer.getFontMetrics(font);
}
Returns the font metrics for the specified font in this component. |
public Color getForeground() {
if (foreground != null)
return foreground;
return parent == null ? null : parent.getForeground();
}
Returns this component's foreground color. If not set, this is inherited
from the parent. |
public Graphics getGraphics() {
if (peer != null)
{
Graphics gfx = peer.getGraphics();
// Create peer for lightweights.
if (gfx == null && parent != null)
{
gfx = parent.getGraphics();
Rectangle bounds = getBounds();
gfx.setClip(bounds);
gfx.translate(bounds.x, bounds.y);
return gfx;
}
gfx.setFont(font);
return gfx;
}
return null;
}
Returns a graphics object for this component. Returns null
if this component is not currently displayed on the screen. |
public GraphicsConfiguration getGraphicsConfiguration() {
return getGraphicsConfigurationImpl();
}
Returns the graphics configuration of this component, if there is one.
If it has not been set, it is inherited from the parent. |
GraphicsConfiguration getGraphicsConfigurationImpl() {
if (peer != null)
{
GraphicsConfiguration config = peer.getGraphicsConfiguration();
if (config != null)
return config;
}
if (parent != null)
return parent.getGraphicsConfiguration();
return null;
}
Implementation method that allows classes such as Canvas and Window to
override the graphics configuration without violating the published API. |
public int getHeight() {
return height;
}
Gets the height of the component. This is more efficient than
getBounds().height or getSize().height. |
public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() {
return (HierarchyBoundsListener[])
AWTEventMulticaster.getListeners(hierarchyBoundsListener,
HierarchyBoundsListener.class);
}
Returns an array of all specified listeners registered on this component. |
public synchronized HierarchyListener[] getHierarchyListeners() {
return (HierarchyListener[])
AWTEventMulticaster.getListeners(hierarchyListener,
HierarchyListener.class);
}
Returns an array of all specified listeners registered on this component. |
public boolean getIgnoreRepaint() {
return ignoreRepaint;
}
Test whether paint events from the operating system are ignored. |
public InputContext getInputContext() {
return parent == null ? null : parent.getInputContext();
}
Gets the input context of this component, which is inherited from the
parent unless this is overridden. |
public synchronized InputMethodListener[] getInputMethodListeners() {
return (InputMethodListener[])
AWTEventMulticaster.getListeners(inputMethodListener,
InputMethodListener.class);
}
Returns an array of all specified listeners registered on this component. |
public InputMethodRequests getInputMethodRequests() {
return null;
}
Returns the input method request handler, for subclasses which support
on-the-spot text input. By default, input methods are handled by AWT,
and this returns null. |
public synchronized KeyListener[] getKeyListeners() {
return (KeyListener[])
AWTEventMulticaster.getListeners(keyListener, KeyListener.class);
}
Returns an array of all specified listeners registered on this component. |
public EventListener[] getListeners(Class listenerType) {
if (listenerType == ComponentListener.class)
return getComponentListeners();
if (listenerType == FocusListener.class)
return getFocusListeners();
if (listenerType == HierarchyListener.class)
return getHierarchyListeners();
if (listenerType == HierarchyBoundsListener.class)
return getHierarchyBoundsListeners();
if (listenerType == KeyListener.class)
return getKeyListeners();
if (listenerType == MouseListener.class)
return getMouseListeners();
if (listenerType == MouseMotionListener.class)
return getMouseMotionListeners();
if (listenerType == MouseWheelListener.class)
return getMouseWheelListeners();
if (listenerType == InputMethodListener.class)
return getInputMethodListeners();
if (listenerType == PropertyChangeListener.class)
return getPropertyChangeListeners();
return (EventListener[]) Array.newInstance(listenerType, 0);
}
Returns all registered EventListener s of the given
listenerType. |
public Locale getLocale() {
if (locale != null)
return locale;
if (parent == null)
throw new IllegalComponentStateException
("Component has no parent: can't determine Locale");
return parent.getLocale();
}
Returns the locale for this component. If this component does not
have a locale, the locale of the parent component is returned. |
public Point getLocation() {
return location ();
}
Returns the location of this component's top left corner relative to
its parent component. This may be outdated, so for synchronous behavior,
you should use a component listner. |
public Point getLocation(Point p) {
if (p == null)
p = new Point();
p.x = x;
p.y = y;
return p;
}
Returns the location of this component. This allows reuse of an existing
point, if p is non-null. |
public Point getLocationOnScreen() {
if (! isShowing())
throw new IllegalComponentStateException("component "
+ getClass().getName()
+ " not showing");
// We know peer != null here.
return peer.getLocationOnScreen();
}
Returns the location of this component's top left corner in screen
coordinates. |
public Dimension getMaximumSize() {
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
}
Returns the component's maximum size. |
public Dimension getMinimumSize() {
return minimumSize();
}
Returns the component's minimum size. |
public synchronized MouseListener[] getMouseListeners() {
return (MouseListener[])
AWTEventMulticaster.getListeners(mouseListener, MouseListener.class);
}
Returns an array of all specified listeners registered on this component. |
public synchronized MouseMotionListener[] getMouseMotionListeners() {
return (MouseMotionListener[])
AWTEventMulticaster.getListeners(mouseMotionListener,
MouseMotionListener.class);
}
Returns an array of all specified listeners registered on this component. |
public synchronized MouseWheelListener[] getMouseWheelListeners() {
return (MouseWheelListener[])
AWTEventMulticaster.getListeners(mouseWheelListener,
MouseWheelListener.class);
}
Returns an array of all specified listeners registered on this component. |
public String getName() {
if (name == null && ! nameExplicitlySet)
name = generateName();
return name;
}
Returns the name of this component. |
public Container getParent() {
return parent;
}
Returns the parent of this component. |
public ComponentPeer getPeer() {
return peer;
} Deprecated! user - programs should not directly manipulate peers; use
#isDisplayable() instead
Returns the native windowing system peer for this component. Only the
platform specific implementation code should call this method. |
public Dimension getPreferredSize() {
return preferredSize();
}
Returns the component's preferred size. |
public PropertyChangeListener[] getPropertyChangeListeners() {
return changeSupport == null ? new PropertyChangeListener[0]
: changeSupport.getPropertyChangeListeners();
}
Returns an array of all specified listeners registered on this component. |
public PropertyChangeListener[] getPropertyChangeListeners(String property) {
return changeSupport == null ? new PropertyChangeListener[0]
: changeSupport.getPropertyChangeListeners(property);
}
Returns an array of all specified listeners on the named property that
are registered on this component. |
public Dimension getSize() {
return size ();
}
Returns the size of this object. |
public Dimension getSize(Dimension d) {
if (d == null)
d = new Dimension();
d.width = width;
d.height = height;
return d;
}
Returns the size of this component. This allows reuse of an existing
dimension, if d is non-null. |
public Toolkit getToolkit() {
if (peer != null)
{
Toolkit tk = peer.getToolkit();
if (tk != null)
return tk;
}
// Get toolkit for lightweight component.
if (parent != null)
return parent.getToolkit();
return Toolkit.getDefaultToolkit();
}
Returns the toolkit in use for this component. The toolkit is associated
with the frame this component belongs to. |
public final Object getTreeLock() {
return treeLock;
}
Returns the object used for synchronization locks on this component
when performing tree and layout functions. |
public int getWidth() {
return width;
}
Gets the width of the component. This is more efficient than
getBounds().width or getSize().width. |
public int getX() {
return x;
}
Gets the x coordinate of the upper left corner. This is more efficient
than getBounds().x or getLocation().x. |
public int getY() {
return y;
}
Gets the y coordinate of the upper left corner. This is more efficient
than getBounds().y or getLocation().y. |
public boolean gotFocus(Event evt,
Object what) {
return false;
} Deprecated! use - #processFocusEvent(FocusEvent) instead
AWT 1.0 GOT_FOCUS event handler. This method is meant to be
overridden by components providing their own GOT_FOCUS handler.
The default implementation simply returns false. |
public boolean handleEvent(Event evt) {
switch (evt.id)
{
// Handle key events.
case Event.KEY_ACTION:
case Event.KEY_PRESS:
return keyDown (evt, evt.key);
case Event.KEY_ACTION_RELEASE:
case Event.KEY_RELEASE:
return keyUp (evt, evt.key);
// Handle mouse events.
case Event.MOUSE_DOWN:
return mouseDown (evt, evt.x, evt.y);
case Event.MOUSE_UP:
return mouseUp (evt, evt.x, evt.y);
case Event.MOUSE_MOVE:
return mouseMove (evt, evt.x, evt.y);
case Event.MOUSE_DRAG:
return mouseDrag (evt, evt.x, evt.y);
case Event.MOUSE_ENTER:
return mouseEnter (evt, evt.x, evt.y);
case Event.MOUSE_EXIT:
return mouseExit (evt, evt.x, evt.y);
// Handle focus events.
case Event.GOT_FOCUS:
return gotFocus (evt, evt.arg);
case Event.LOST_FOCUS:
return lostFocus (evt, evt.arg);
// Handle action event.
case Event.ACTION_EVENT:
return action (evt, evt.arg);
}
// Unknown event.
return false;
} Deprecated! use - #processEvent(AWTEvent) instead
AWT 1.0 event handler.
This method calls one of the event-specific handler methods. For
example for key events, either #keyDown(Event,int)
or #keyUp(Event,int) is called. A derived
component can override one of these event-specific methods if it
only needs to handle certain event types. Otherwise it can
override handleEvent itself and handle any event. |
public boolean hasFocus() {
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
Component focusOwner = manager.getFocusOwner ();
return this == focusOwner;
}
Tests if this component is the focus owner. Use () instead. |
public void hide() {
if (isVisible())
{
// Avoid NullPointerExceptions by creating a local reference.
ComponentPeer currentPeer=peer;
if (currentPeer != null)
currentPeer.setVisible(false);
boolean wasShowing = isShowing();
this.visible = false;
// The JDK repaints the component before invalidating the parent.
// So do we.
if (wasShowing)
repaint();
// Invalidate the parent if we have one. The component itself must
// not be invalidated. We also avoid NullPointerException with
// a local reference here.
Container currentParent = parent;
if (currentParent != null)
currentParent.invalidate();
ComponentEvent ce =
new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
getToolkit().getSystemEventQueue().postEvent(ce);
}
} Deprecated! use - #setVisible(boolean) instead
Hides this component so that it is no longer shown on the screen. |
public boolean imageUpdate(Image img,
int flags,
int x,
int y,
int w,
int h) {
if ((flags & (FRAMEBITS | ALLBITS)) != 0)
repaint();
else if ((flags & SOMEBITS) != 0)
{
if (incrementalDraw)
{
if (redrawRate != null)
{
long tm = redrawRate.longValue();
if (tm < 0)
tm = 0;
repaint(tm);
}
else
repaint(100);
}
}
return (flags & (ALLBITS | ABORT | ERROR)) == 0;
}
|
public boolean inside(int x,
int y) {
return x >= 0 && y >= 0 && x < width && y < height;
} Deprecated! use - #contains(int, int) instead
Tests whether or not the specified point is contained within this
component. Coordinates are relative to this component. |
public void invalidate() {
valid = false;
prefSize = null;
minSize = null;
if (parent != null && parent.isValid())
parent.invalidate();
}
Invalidates this component and all of its parent components. This will
cause them to have their layout redone. This is called frequently, so
make it fast. |
public boolean isBackgroundSet() {
return background != null;
}
Tests if the background was explicitly set, or just inherited from the
parent. |
public boolean isCursorSet() {
return cursor != null;
}
Tests if the cursor was explicitly set, or just inherited from the parent. |
public boolean isDisplayable() {
return peer != null;
}
Tests if the component is displayable. It must be connected to a native
screen resource. This reduces to checking that peer is not null. A
containment hierarchy is made displayable when a window is packed or
made visible. |
public boolean isDoubleBuffered() {
return false;
}
Checks if this image is painted to an offscreen image buffer that is
later copied to screen (double buffering reduces flicker). This version
returns false, so subclasses must override it if they provide double
buffering. |
public boolean isEnabled() {
return enabled;
}
Tests whether or not this component is enabled. Components are enabled
by default, and must be enabled to receive user input or generate events. |
public boolean isFocusCycleRoot(Container c) {
return c == getFocusCycleRootAncestor ();
}
Tests if the container is the ancestor of the focus cycle that
this component belongs to. |
public boolean isFocusOwner() {
return hasFocus ();
}
Tests if this component is the focus owner. |
public boolean isFocusTraversable() {
return enabled && visible && (peer == null || isLightweight() || peer.isFocusTraversable());
} Deprecated! use - #isFocusable() instead
Tests whether or not this component is in the group that can be
traversed using the keyboard traversal mechanism (such as the TAB key). |
public boolean isFocusable() {
return focusable;
}
Tests if this component can receive focus. |
public boolean isFontSet() {
return font != null;
}
Tests if the font was explicitly set, or just inherited from the parent. |
public boolean isForegroundSet() {
return foreground != null;
}
Tests if the foreground was explicitly set, or just inherited from the
parent. |
public boolean isLightweight() {
return peer instanceof LightweightPeer;
}
Return whether the component is lightweight. That means the component has
no native peer, but is displayable. This applies to subclasses of
Component not in this package, such as javax.swing. |
public boolean isOpaque() {
return ! isLightweight();
}
Tests if this component is opaque. All "heavyweight" (natively-drawn)
components are opaque. A component is opaque if it draws all pixels in
the bounds; a lightweight component is partially transparent if it lets
pixels underneath show through. Subclasses that guarantee that all pixels
will be drawn should override this. |
public boolean isShowing() {
if (! visible || peer == null)
return false;
return parent == null ? false : parent.isShowing();
}
Tests whether or not this component is actually being shown on
the screen. This will be true if and only if it this component is
visible and its parent components are all visible. |
public boolean isValid() {
return valid;
}
Tests whether or not this component is valid. A invalid component needs
to have its layout redone. |
public boolean isVisible() {
return visible;
}
Tests whether or not this component is visible. Except for top-level
frames, components are initially visible. |
public boolean keyDown(Event evt,
int key) {
return false;
} Deprecated! use - #processKeyEvent(KeyEvent) instead
AWT 1.0 KEY_PRESS and KEY_ACTION event handler. This method is
meant to be overridden by components providing their own key
press handler. The default implementation simply returns false. |
public boolean keyUp(Event evt,
int key) {
return false;
} Deprecated! use - #processKeyEvent(KeyEvent) instead
AWT 1.0 KEY_RELEASE and KEY_ACTION_RELEASE event handler. This
method is meant to be overridden by components providing their
own key release handler. The default implementation simply
returns false. |
public void layout() {
// Nothing to do unless we're a container.
} Deprecated! use - #doLayout() instead
Calls the layout manager to re-layout the component. This is called
during validation of a container in most cases. |
public void list() {
list(System.out, 0);
}
Prints a listing of this component to System.out. |
public void list(PrintStream out) {
list(out, 0);
}
Prints a listing of this component to the specified print stream. |
public void list(PrintWriter out) {
list(out, 0);
}
Prints a listing of this component to the specified print writer. |
public void list(PrintStream out,
int indent) {
for (int i = 0; i < indent; ++i)
out.print(' ");
out.println(toString());
}
Prints a listing of this component to the specified print stream,
starting at the specified indentation point. |
public void list(PrintWriter out,
int indent) {
for (int i = 0; i < indent; ++i)
out.print(' ");
out.println(toString());
}
Prints a listing of this component to the specified print writer,
starting at the specified indentation point. |
public Component locate(int x,
int y) {
return contains (x, y) ? this : null;
} Deprecated! use - #getComponentAt(int, int) instead
Returns the component occupying the position (x,y). This will either
be this component, an immediate child component, or null
if neither of the first two occupies the specified location. |
public Point location() {
return new Point (x, y);
} Deprecated! use - #getLocation() instead
Returns the location of this component's top left corner relative to
its parent component. |
public boolean lostFocus(Event evt,
Object what) {
return false;
} Deprecated! use - #processFocusEvent(FocusEvent) instead
AWT 1.0 LOST_FOCUS event handler. This method is meant to be
overridden by components providing their own LOST_FOCUS handler.
The default implementation simply returns false. |
public Dimension minimumSize() {
if (minSize == null)
minSize = (peer != null ? peer.getMinimumSize()
: new Dimension(width, height));
return minSize;
} Deprecated! use - #getMinimumSize() instead
Returns the component's minimum size. |
public boolean mouseDown(Event evt,
int x,
int y) {
return false;
} Deprecated! use - #processMouseEvent(MouseEvent) instead
AWT 1.0 MOUSE_DOWN event handler. This method is meant to be
overridden by components providing their own MOUSE_DOWN handler.
The default implementation simply returns false. |
public boolean mouseDrag(Event evt,
int x,
int y) {
return false;
} Deprecated! use - #processMouseMotionEvent(MouseEvent) instead
AWT 1.0 MOUSE_DRAG event handler. This method is meant to be
overridden by components providing their own MOUSE_DRAG handler.
The default implementation simply returns false. |
public boolean mouseEnter(Event evt,
int x,
int y) {
return false;
} Deprecated! use - #processMouseEvent(MouseEvent) instead
AWT 1.0 MOUSE_ENTER event handler. This method is meant to be
overridden by components providing their own MOUSE_ENTER handler.
The default implementation simply returns false. |
public boolean mouseExit(Event evt,
int x,
int y) {
return false;
} Deprecated! use - #processMouseEvent(MouseEvent) instead
AWT 1.0 MOUSE_EXIT event handler. This method is meant to be
overridden by components providing their own MOUSE_EXIT handler.
The default implementation simply returns false. |
public boolean mouseMove(Event evt,
int x,
int y) {
return false;
} Deprecated! use - #processMouseMotionEvent(MouseEvent) instead
AWT 1.0 MOUSE_MOVE event handler. This method is meant to be
overridden by components providing their own MOUSE_MOVE handler.
The default implementation simply returns false. |
public boolean mouseUp(Event evt,
int x,
int y) {
return false;
} Deprecated! use - #processMouseEvent(MouseEvent) instead
AWT 1.0 MOUSE_UP event handler. This method is meant to be
overridden by components providing their own MOUSE_UP handler.
The default implementation simply returns false. |
public void move(int x,
int y) {
setBounds(x, y, this.width, this.height);
} Deprecated! use - #setLocation(int, int) instead
Moves this component to the specified location, relative to the parent's
coordinates. The coordinates are the new upper left corner of this
component. |
public void nextFocus() {
// Find the nearest valid (== showing && focusable && enabled) focus
// cycle root ancestor and the focused component in it.
Container focusRoot = getFocusCycleRootAncestor();
Component focusComp = this;
while (focusRoot != null
&& ! (focusRoot.isShowing() && focusRoot.isFocusable()
&& focusRoot.isEnabled()))
{
focusComp = focusRoot;
focusRoot = focusComp.getFocusCycleRootAncestor();
}
if (focusRoot != null)
{
// First try to get the componentBefore from the policy.
FocusTraversalPolicy policy = focusRoot.getFocusTraversalPolicy();
Component nextFocus = policy.getComponentAfter(focusRoot, focusComp);
// If this fails, then ask for the defaultComponent.
if (nextFocus == null)
nextFocus = policy.getDefaultComponent(focusRoot);
// Request focus on this component, if not null.
if (nextFocus != null)
nextFocus.requestFocus();
}
} Deprecated! use - () instead
AWT 1.0 focus event processor. Transfers focus to the next
component in the focus traversal order, as though this were the
current focus owner. |
public void paint(Graphics g) {
// This is a callback method and is meant to be overridden by subclasses
// that want to perform custom painting.
}
Paints this component on the screen. The clipping region in the graphics
context will indicate the region that requires painting. This is called
whenever the component first shows, or needs to be repaired because
something was temporarily drawn on top. It is not necessary for
subclasses to call super.paint(g). Components with no area
are not painted. |
public void paintAll(Graphics g) {
if (! visible)
return;
paint(g);
}
Paints this entire component, including any sub-components. |
protected String paramString() {
StringBuffer param = new StringBuffer();
String name = getName();
if (name != null)
param.append(name).append(",");
param.append(x).append(",").append(y).append(",").append(width)
.append("x").append(height);
if (! isValid())
param.append(",invalid");
if (! isVisible())
param.append(",invisible");
if (! isEnabled())
param.append(",disabled");
if (! isOpaque())
param.append(",translucent");
if (isDoubleBuffered())
param.append(",doublebuffered");
if (parent == null)
param.append(",parent=null");
else
param.append(",parent=").append(parent.getName());
return param.toString();
}
Returns a debugging string representing this component. The string may
be empty but not null. |
public boolean postEvent(Event e) {
boolean handled = handleEvent (e);
if (!handled && getParent() != null)
// FIXME: need to translate event coordinates to parent's
// coordinate space.
handled = getParent ().postEvent (e);
return handled;
} Deprecated! use - #dispatchEvent(AWTEvent) instead
AWT 1.0 event handler.
This method simply calls handleEvent and returns the result. |
public Dimension preferredSize() {
if (prefSize == null)
{
if (peer == null)
prefSize = minimumSize();
else
prefSize = peer.getPreferredSize();
}
return prefSize;
} Deprecated! use - #getPreferredSize() instead
Returns the component's preferred size. |
public boolean prepareImage(Image image,
ImageObserver observer) {
return prepareImage(image, image.getWidth(observer),
image.getHeight(observer), observer);
}
Prepares the specified image for rendering on this component. |
public boolean prepareImage(Image image,
int width,
int height,
ImageObserver observer) {
if (peer != null)
return peer.prepareImage(image, width, height, observer);
else
return getToolkit().prepareImage(image, width, height, observer);
}
Prepares the specified image for rendering on this component at the
specified scaled width and height |
public void print(Graphics g) {
paint(g);
}
Prints this component. This method is provided so that printing can be
done in a different manner from painting. However, the implementation
in this class simply calls the paint() method. |
public void printAll(Graphics g) {
paintAll(g);
}
Prints this component, including all sub-components. This method is
provided so that printing can be done in a different manner from
painting. However, the implementation in this class simply calls the
paintAll() method. |
protected void processComponentEvent(ComponentEvent e) {
if (componentListener == null)
return;
switch (e.id)
{
case ComponentEvent.COMPONENT_HIDDEN:
componentListener.componentHidden(e);
break;
case ComponentEvent.COMPONENT_MOVED:
componentListener.componentMoved(e);
break;
case ComponentEvent.COMPONENT_RESIZED:
componentListener.componentResized(e);
break;
case ComponentEvent.COMPONENT_SHOWN:
componentListener.componentShown(e);
break;
}
}
Called when a component event is dispatched and component events are
enabled. This method passes the event along to any listeners
that are attached. |
protected void processEvent(AWTEvent e) {
/* Note: the order of these if statements are
important. Subclasses must be checked first. Eg. MouseEvent
must be checked before ComponentEvent, since a MouseEvent
object is also an instance of a ComponentEvent. */
if (e instanceof FocusEvent)
processFocusEvent((FocusEvent) e);
else if (e instanceof MouseWheelEvent)
processMouseWheelEvent((MouseWheelEvent) e);
else if (e instanceof MouseEvent)
{
if (e.id == MouseEvent.MOUSE_MOVED
|| e.id == MouseEvent.MOUSE_DRAGGED)
processMouseMotionEvent((MouseEvent) e);
else
processMouseEvent((MouseEvent) e);
}
else if (e instanceof KeyEvent)
processKeyEvent((KeyEvent) e);
else if (e instanceof InputMethodEvent)
processInputMethodEvent((InputMethodEvent) e);
else if (e instanceof ComponentEvent)
processComponentEvent((ComponentEvent) e);
else if (e instanceof HierarchyEvent)
{
if (e.id == HierarchyEvent.HIERARCHY_CHANGED)
processHierarchyEvent((HierarchyEvent) e);
else
processHierarchyBoundsEvent((HierarchyEvent) e);
}
}
Processes the specified event. In this class, this method simply
calls one of the more specific event handlers. |
protected void processFocusEvent(FocusEvent e) {
if (focusListener == null)
return;
switch (e.id)
{
case FocusEvent.FOCUS_GAINED:
focusListener.focusGained(e);
break;
case FocusEvent.FOCUS_LOST:
focusListener.focusLost(e);
break;
}
}
Called when a focus event is dispatched and component events are
enabled. This method passes the event along to any listeners
that are attached. |
protected void processHierarchyBoundsEvent(HierarchyEvent e) {
if (hierarchyBoundsListener == null)
return;
switch (e.id)
{
case HierarchyEvent.ANCESTOR_MOVED:
hierarchyBoundsListener.ancestorMoved(e);
break;
case HierarchyEvent.ANCESTOR_RESIZED:
hierarchyBoundsListener.ancestorResized(e);
break;
}
}
Called when a hierarchy bounds event is dispatched and component events
are enabled. This method passes the event along to any listeners that are
attached. |
protected void processHierarchyEvent(HierarchyEvent e) {
if (hierarchyListener == null)
return;
if (e.id == HierarchyEvent.HIERARCHY_CHANGED)
hierarchyListener.hierarchyChanged(e);
}
Called when a hierarchy change event is dispatched and component events
are enabled. This method passes the event along to any listeners that are
attached. |
protected void processInputMethodEvent(InputMethodEvent e) {
if (inputMethodListener == null)
return;
switch (e.id)
{
case InputMethodEvent.CARET_POSITION_CHANGED:
inputMethodListener.caretPositionChanged(e);
break;
case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
inputMethodListener.inputMethodTextChanged(e);
break;
}
}
Called when an input method event is dispatched and component events are
enabled. This method passes the event along to any listeners that are
attached. |
protected void processKeyEvent(KeyEvent e) {
if (keyListener == null)
return;
switch (e.id)
{
case KeyEvent.KEY_PRESSED:
keyListener.keyPressed(e);
break;
case KeyEvent.KEY_RELEASED:
keyListener.keyReleased(e);
break;
case KeyEvent.KEY_TYPED:
keyListener.keyTyped(e);
break;
}
}
Called when a key event is dispatched and component events are
enabled. This method passes the event along to any listeners
that are attached. |
protected void processMouseEvent(MouseEvent e) {
if (mouseListener == null)
return;
switch (e.id)
{
case MouseEvent.MOUSE_CLICKED:
mouseListener.mouseClicked(e);
break;
case MouseEvent.MOUSE_ENTERED:
if( isLightweight() )
setCursor( getCursor() );
mouseListener.mouseEntered(e);
break;
case MouseEvent.MOUSE_EXITED:
mouseListener.mouseExited(e);
break;
case MouseEvent.MOUSE_PRESSED:
mouseListener.mousePressed(e);
break;
case MouseEvent.MOUSE_RELEASED:
mouseListener.mouseReleased(e);
break;
}
}
Called when a regular mouse event is dispatched and component events are
enabled. This method passes the event along to any listeners
that are attached. |
protected void processMouseMotionEvent(MouseEvent e) {
if (mouseMotionListener == null)
return;
switch (e.id)
{
case MouseEvent.MOUSE_DRAGGED:
mouseMotionListener.mouseDragged(e);
break;
case MouseEvent.MOUSE_MOVED:
mouseMotionListener.mouseMoved(e);
break;
}
e.consume();
}
Called when a mouse motion event is dispatched and component events are
enabled. This method passes the event along to any listeners
that are attached. |
protected void processMouseWheelEvent(MouseWheelEvent e) {
if (mouseWheelListener != null
&& e.id == MouseEvent.MOUSE_WHEEL)
{
mouseWheelListener.mouseWheelMoved(e);
e.consume();
}
}
Called when a mouse wheel event is dispatched and component events are
enabled. This method passes the event along to any listeners that are
attached. |
public synchronized void remove(MenuComponent popup) {
if (popups != null)
popups.remove(popup);
}
Removes the specified popup menu from this component. |
public synchronized void removeComponentListener(ComponentListener listener) {
componentListener = AWTEventMulticaster.remove(componentListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public synchronized void removeFocusListener(FocusListener listener) {
focusListener = AWTEventMulticaster.remove(focusListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public synchronized void removeHierarchyBoundsListener(HierarchyBoundsListener listener) {
hierarchyBoundsListener =
AWTEventMulticaster.remove(hierarchyBoundsListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public synchronized void removeHierarchyListener(HierarchyListener listener) {
hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public synchronized void removeInputMethodListener(InputMethodListener listener) {
inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public synchronized void removeKeyListener(KeyListener listener) {
keyListener = AWTEventMulticaster.remove(keyListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public synchronized void removeMouseListener(MouseListener listener) {
mouseListener = AWTEventMulticaster.remove(mouseListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public synchronized void removeMouseMotionListener(MouseMotionListener listener) {
mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public synchronized void removeMouseWheelListener(MouseWheelListener listener) {
mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, listener);
}
Removes the specified listener from the component. This is harmless if
the listener was not previously registered. |
public void removeNotify() {
// We null our peer field before disposing of it, such that if we're
// not the event dispatch thread and the dispatch thread is awoken by
// the dispose call, there will be no race checking the peer's null
// status.
ComponentPeer tmp = peer;
peer = null;
if (tmp != null)
{
tmp.hide();
tmp.dispose();
}
}
Called to inform this component is has been removed from its
container. Its native peer - if any - is destroyed at this time.
This method is called automatically by the AWT system and should
not be called by user level code. |
public void removePropertyChangeListener(PropertyChangeListener listener) {
if (changeSupport != null)
changeSupport.removePropertyChangeListener(listener);
}
Removes the specified property listener from the component. This is
harmless if the listener was not previously registered. |
public void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener) {
if (changeSupport != null)
changeSupport.removePropertyChangeListener(propertyName, listener);
}
Removes the specified property listener on a particular property from
the component. This is harmless if the listener was not previously
registered. |
public void repaint() {
repaint(0, 0, 0, width, height);
}
Repaint this entire component. The update() method
on this component will be called as soon as possible. |
public void repaint(long tm) {
repaint(tm, 0, 0, width, height);
}
Repaint this entire component. The update() method on this
component will be called in approximate the specified number of
milliseconds. |
public void repaint(int x,
int y,
int w,
int h) {
repaint(0, x, y, w, h);
}
Repaints the specified rectangular region within this component. The
update method on this component will be called as soon as
possible. The coordinates are relative to this component. |
public void repaint(long tm,
int x,
int y,
int width,
int height) {
if (isShowing())
{
ComponentPeer p = peer;
if (p != null)
p.repaint(tm, x, y, width, height);
}
}
Repaints the specified rectangular region within this component. The
update method on this component will be called in
approximately the specified number of milliseconds. The coordinates
are relative to this component. |
public void requestFocus() {
if (isDisplayable ()
&& isShowing ()
&& isFocusable ())
{
synchronized (getTreeLock ())
{
// Find this Component's top-level ancestor.
Container parent = (this instanceof Container) ? (Container) this
: getParent();
while (parent != null
&& !(parent instanceof Window))
parent = parent.getParent ();
if (parent == null)
return;
Window toplevel = (Window) parent;
if (toplevel.isFocusableWindow ())
{
if (peer != null && !isLightweight())
// This call will cause a FOCUS_GAINED event to be
// posted to the system event queue if the native
// windowing system grants the focus request.
peer.requestFocus ();
else
{
// Either our peer hasn't been created yet or we're a
// lightweight component. In either case we want to
// post a FOCUS_GAINED event.
EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
synchronized (eq)
{
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
if (currentFocusOwner != null)
{
eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
false, this));
eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false,
currentFocusOwner));
}
else
eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false));
}
}
}
else
pendingFocusRequest = new FocusEvent(this, FocusEvent.FOCUS_GAINED);
}
}
}
Request that this Component be given the keyboard input focus and
that its top-level ancestor become the focused Window.
For the request to be granted, the Component must be focusable,
displayable and showing and the top-level Window to which it
belongs must be focusable. If the request is initially denied on
the basis that the top-level Window is not focusable, the request
will be remembered and granted when the Window does become
focused.
Never assume that this Component is the focus owner until it
receives a FOCUS_GAINED event.
The behaviour of this method is platform-dependent.
#requestFocusInWindow() should be used instead. |
protected boolean requestFocus(boolean temporary) {
if (isDisplayable ()
&& isShowing ()
&& isFocusable ())
{
synchronized (getTreeLock ())
{
// Find this Component's top-level ancestor.
Container parent = getParent ();
while (parent != null
&& !(parent instanceof Window))
parent = parent.getParent ();
Window toplevel = (Window) parent;
if (toplevel.isFocusableWindow ())
{
if (peer != null && !isLightweight())
// This call will cause a FOCUS_GAINED event to be
// posted to the system event queue if the native
// windowing system grants the focus request.
peer.requestFocus ();
else
{
// Either our peer hasn't been created yet or we're a
// lightweight component. In either case we want to
// post a FOCUS_GAINED event.
EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
synchronized (eq)
{
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
if (currentFocusOwner != null)
{
eq.postEvent (new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
temporary, this));
eq.postEvent (new FocusEvent(this,
FocusEvent.FOCUS_GAINED,
temporary,
currentFocusOwner));
}
else
eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));
}
}
}
else
// FIXME: need to add a focus listener to our top-level
// ancestor, so that we can post this event when it becomes
// the focused window.
pendingFocusRequest = new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary);
}
}
// Always return true.
return true;
}
Request that this Component be given the keyboard input focus and
that its top-level ancestor become the focused Window.
For the request to be granted, the Component must be focusable,
displayable and showing and the top-level Window to which it
belongs must be focusable. If the request is initially denied on
the basis that the top-level Window is not focusable, the request
will be remembered and granted when the Window does become
focused.
Never assume that this Component is the focus owner until it
receives a FOCUS_GAINED event.
The behaviour of this method is platform-dependent.
#requestFocusInWindow() should be used instead.
If the return value is false, the request is guaranteed to fail.
If the return value is true, the request will succeed unless it
is vetoed or something in the native windowing system intervenes,
preventing this Component's top-level ancestor from becoming
focused. This method is meant to be called by derived
lightweight Components that want to avoid unnecessary repainting
when they know a given focus transfer need only be temporary. |
public boolean requestFocusInWindow() {
return requestFocusInWindow (false);
}
Request that this component be given the keyboard input focus, if
its top-level ancestor is the currently focused Window. A
FOCUS_GAINED event will be fired if and only if this
request is successful. To be successful, the component must be
displayable, showing, and focusable, and its ancestor top-level
Window must be focused.
If the return value is false, the request is guaranteed to fail.
If the return value is true, the request will succeed unless it
is vetoed or something in the native windowing system intervenes,
preventing this Component's top-level ancestor from becoming
focused. |
protected boolean requestFocusInWindow(boolean temporary) {
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
Window focusedWindow = manager.getFocusedWindow ();
if (isDisplayable ()
&& isShowing ()
&& isFocusable ())
{
if (focusedWindow != null)
{
synchronized (getTreeLock ())
{
Container parent = getParent ();
while (parent != null
&& !(parent instanceof Window))
parent = parent.getParent ();
Window toplevel = (Window) parent;
// Check if top-level ancestor is currently focused window.
if (focusedWindow == toplevel)
{
if (peer != null
&& !isLightweight()
&& !(this instanceof Window))
// This call will cause a FOCUS_GAINED event to be
// posted to the system event queue if the native
// windowing system grants the focus request.
peer.requestFocus ();
else
{
// Either our peer hasn't been created yet or we're a
// lightweight component. In either case we want to
// post a FOCUS_GAINED event.
EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
synchronized (eq)
{
Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
if (currentFocusOwner != null)
{
eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
temporary, this));
eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary,
currentFocusOwner));
}
else
eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));
}
}
}
else
return false;
}
}
return true;
}
return false;
}
Request that this component be given the keyboard input focus, if
its top-level ancestor is the currently focused Window. A
FOCUS_GAINED event will be fired if and only if this
request is successful. To be successful, the component must be
displayable, showing, and focusable, and its ancestor top-level
Window must be focused.
If the return value is false, the request is guaranteed to fail.
If the return value is true, the request will succeed unless it
is vetoed or something in the native windowing system intervenes,
preventing this Component's top-level ancestor from becoming
focused. This method is meant to be called by derived
lightweight Components that want to avoid unnecessary repainting
when they know a given focus transfer need only be temporary. |
public void reshape(int x,
int y,
int width,
int height) {
int oldx = this.x;
int oldy = this.y;
int oldwidth = this.width;
int oldheight = this.height;
if (this.x == x && this.y == y && this.width == width
&& this.height == height)
return;
invalidate();
this.x = x;
this.y = y;
this.width = width;
this.height = height;
if (peer != null)
peer.setBounds (x, y, width, height);
// Erase old bounds and repaint new bounds for lightweights.
if (isLightweight() && isShowing())
{
if (parent != null)
{
Rectangle oldBounds = new Rectangle(oldx, oldy, oldwidth,
oldheight);
Rectangle newBounds = new Rectangle(x, y, width, height);
Rectangle destroyed = oldBounds.union(newBounds);
if (!destroyed.isEmpty())
parent.repaint(0, destroyed.x, destroyed.y, destroyed.width,
destroyed.height);
}
}
// Only post event if this component is visible and has changed size.
if (isShowing ()
&& (oldx != x || oldy != y))
{
ComponentEvent ce = new ComponentEvent(this,
ComponentEvent.COMPONENT_MOVED);
getToolkit().getSystemEventQueue().postEvent(ce);
}
if (isShowing ()
&& (oldwidth != width || oldheight != height))
{
ComponentEvent ce = new ComponentEvent(this,
ComponentEvent.COMPONENT_RESIZED);
getToolkit().getSystemEventQueue().postEvent(ce);
}
} Deprecated! use - #setBounds(int, int, int, int) instead
Sets the bounding rectangle for this component to the specified values.
Note that these coordinates are relative to the parent, not to the screen. |
public void resize(Dimension d) {
resize (d.width, d.height);
} Deprecated! use - #setSize(Dimension) instead
Sets the size of this component to the specified value. |
public void resize(int width,
int height) {
setBounds(this.x, this.y, width, height);
} Deprecated! use - #setSize(int, int) instead
Sets the size of this component to the specified value. |
public void setBackground(Color c) {
// return if the background is already set to that color.
if ((c != null) && c.equals(background))
return;
Color previous = background;
background = c;
if (peer != null && c != null)
peer.setBackground(c);
firePropertyChange("background", previous, c);
}
Sets this component's background color to the specified color. The parts
of the component affected by the background color may by system dependent.
This is a bound property. |
public void setBounds(Rectangle r) {
setBounds (r.x, r.y, r.width, r.height);
}
Sets the bounding rectangle for this component to the specified
rectangle. Note that these coordinates are relative to the parent, not
to the screen. |
public void setBounds(int x,
int y,
int w,
int h) {
reshape (x, y, w, h);
}
Sets the bounding rectangle for this component to the specified values.
Note that these coordinates are relative to the parent, not to the screen. |
public void setComponentOrientation(ComponentOrientation o) {
if (o == null)
throw new NullPointerException();
ComponentOrientation oldOrientation = orientation;
orientation = o;
firePropertyChange("componentOrientation", oldOrientation, o);
}
Sets the text layout orientation of this component. New components default
to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects only
the current component, while
#applyComponentOrientation(ComponentOrientation) affects the
entire hierarchy. |
public void setCursor(Cursor cursor) {
this.cursor = cursor;
if (peer != null)
peer.setCursor(cursor);
}
Sets the cursor for this component to the specified cursor. The cursor
is displayed when the point is contained by the component, and the
component is visible, displayable, and enabled. This is inherited by
subcomponents unless they set their own cursor. |
public void setDropTarget(DropTarget dt) {
this.dropTarget = dt;
}
Set the associated drag-and-drop target, which receives events when this
is enabled. |
public void setEnabled(boolean enabled) {
enable(enabled);
}
Enables or disables this component. The component must be enabled to
receive events (except that lightweight components always receive mouse
events). |
public void setFocusTraversalKeys(int id,
Set keystrokes) {
if (keystrokes == null)
{
Container parent = getParent ();
while (parent != null)
{
if (parent.areFocusTraversalKeysSet (id))
{
keystrokes = parent.getFocusTraversalKeys (id);
break;
}
parent = parent.getParent ();
}
if (keystrokes == null)
keystrokes = KeyboardFocusManager.getCurrentKeyboardFocusManager ().
getDefaultFocusTraversalKeys (id);
}
Set sa;
Set sb;
String name;
switch (id)
{
case KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS:
sa = getFocusTraversalKeys
(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
sb = getFocusTraversalKeys
(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
name = "forwardFocusTraversalKeys";
break;
case KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS:
sa = getFocusTraversalKeys
(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
sb = getFocusTraversalKeys
(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
name = "backwardFocusTraversalKeys";
break;
case KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS:
sa = getFocusTraversalKeys
(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
sb = getFocusTraversalKeys
(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
name = "upCycleFocusTraversalKeys";
break;
default:
throw new IllegalArgumentException ();
}
int i = keystrokes.size ();
Iterator iter = keystrokes.iterator ();
while (--i >= 0)
{
Object o = iter.next ();
if (!(o instanceof AWTKeyStroke)
|| sa.contains (o) || sb.contains (o)
|| ((AWTKeyStroke) o).keyCode == KeyEvent.VK_UNDEFINED)
throw new IllegalArgumentException ();
}
if (focusTraversalKeys == null)
focusTraversalKeys = new Set[3];
keystrokes = Collections.unmodifiableSet (new HashSet (keystrokes));
firePropertyChange (name, focusTraversalKeys[id], keystrokes);
focusTraversalKeys[id] = keystrokes;
}
Sets the focus traversal keys for one of the three focus
traversal directions supported by Components:
KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS ,
KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS , or
KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS . Normally, the
default values should match the operating system's native
choices. To disable a given traversal, use
Collections.EMPTY_SET. The event dispatcher will
consume PRESSED, RELEASED, and TYPED events for the specified
key, although focus can only transfer on PRESSED or RELEASED.
The defaults are:
| Identifier | Meaning | Default |
| KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS |
Normal forward traversal |
TAB on KEY_PRESSED, Ctrl-TAB on KEY_PRESSED |
| KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS |
Normal backward traversal |
Shift-TAB on KEY_PRESSED, Ctrl-Shift-TAB on KEY_PRESSED |
| KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS |
Go up a traversal cycle | None |
If keystrokes is null, this component's focus traversal key set
is inherited from one of its ancestors. If none of its ancestors
has its own set of focus traversal keys, the focus traversal keys
are set to the defaults retrieved from the current
KeyboardFocusManager. If not null, the set must contain only
AWTKeyStrokes that are not already focus keys and are not
KEY_TYPED events. |
public void setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled) {
firePropertyChange ("focusTraversalKeysEnabled",
this.focusTraversalKeysEnabled,
focusTraversalKeysEnabled);
this.focusTraversalKeysEnabled = focusTraversalKeysEnabled;
}
Enable or disable focus traversal keys on this Component. If
they are, then the keyboard focus manager consumes and acts on
key press and release events that trigger focus traversal, and
discards the corresponding key typed events. If focus traversal
keys are disabled, then all key events that would otherwise
trigger focus traversal are sent to this Component. |
public void setFocusable(boolean focusable) {
firePropertyChange("focusable", this.focusable, focusable);
this.focusable = focusable;
this.isFocusTraversableOverridden = 1;
}
|
public void setFont(Font newFont) {
if((newFont != null && (font == null || !font.equals(newFont)))
|| newFont == null)
{
Font oldFont = font;
font = newFont;
if (peer != null)
peer.setFont(font);
firePropertyChange("font", oldFont, newFont);
invalidate();
}
}
Sets the font for this component to the specified font. This is a bound
property. |
public void setForeground(Color c) {
if (peer != null)
peer.setForeground(c);
Color previous = foreground;
foreground = c;
firePropertyChange("foreground", previous, c);
}
Sets this component's foreground color to the specified color. This is a
bound property. |
public void setIgnoreRepaint(boolean ignoreRepaint) {
this.ignoreRepaint = ignoreRepaint;
}
Sets whether paint messages delivered by the operating system should be
ignored. This does not affect messages from AWT, except for those
triggered by OS messages. Setting this to true can allow faster
performance in full-screen mode or page-flipping. |
public void setLocale(Locale newLocale) {
if (locale == newLocale)
return;
Locale oldLocale = locale;
locale = newLocale;
firePropertyChange("locale", oldLocale, newLocale);
// New writing/layout direction or more/less room for localized labels.
invalidate();
}
Sets the locale for this component to the specified locale. This is a
bound property. |
public void setLocation(Point p) {
setLocation(p.x, p.y);
}
Moves this component to the specified location, relative to the parent's
coordinates. The coordinates are the new upper left corner of this
component. |
public void setLocation(int x,
int y) {
move (x, y);
}
Moves this component to the specified location, relative to the parent's
coordinates. The coordinates are the new upper left corner of this
component. |
public void setName(String name) {
nameExplicitlySet = true;
this.name = name;
}
Sets the name of this component to the specified name. |
final void setPeer(ComponentPeer peer) {
this.peer = peer;
}
Sets the peer for this component. |
public void setSize(Dimension d) {
resize (d);
}
Sets the size of this component to the specified value. |
public void setSize(int width,
int height) {
resize (width, height);
}
Sets the size of this component to the specified width and height. |
public void setVisible(boolean visible) {
// Inspection by subclassing shows that Sun's implementation calls
// show(boolean) which then calls show() or hide(). It is the show()
// method that is overriden in subclasses like Window.
show(visible);
}
Makes this component visible or invisible. Note that it wtill might
not show the component, if a parent is invisible. |
public void show() {
// We must set visible before showing the peer. Otherwise the
// peer could post paint events before visible is true, in which
// case lightweight components are not initially painted --
// Container.paint first calls isShowing () before painting itself
// and its children.
if(!isVisible())
{
this.visible = true;
// Avoid NullPointerExceptions by creating a local reference.
ComponentPeer currentPeer=peer;
if (currentPeer != null)
currentPeer.show();
// The JDK repaints the component before invalidating the parent.
// So do we.
if (isShowing() && isLightweight())
repaint();
// Invalidate the parent if we have one. The component itself must
// not be invalidated. We also avoid NullPointerException with
// a local reference here.
Container currentParent = parent;
if (currentParent != null)
currentParent.invalidate();
ComponentEvent ce =
new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
getToolkit().getSystemEventQueue().postEvent(ce);
}
} Deprecated! use - #setVisible(boolean) instead
Makes this component visible on the screen. |
public void show(boolean visible) {
if (visible)
show();
else
hide();
} Deprecated! use - #setVisible(boolean) instead
Makes this component visible or invisible. |
public Dimension size() {
return new Dimension (width, height);
} Deprecated! use - #getSize() instead
Returns the size of this object. |
public String toString() {
return getClass().getName() + '[" + paramString() + ']";
}
Returns a string representation of this component. This is implemented
as getClass().getName() + '[' + paramString() + ']'. |
public void transferFocus() {
nextFocus ();
}
Transfers focus to the next component in the focus traversal
order, as though this were the current focus owner. |
public void transferFocusBackward() {
// Find the nearest valid (== showing && focusable && enabled) focus
// cycle root ancestor and the focused component in it.
Container focusRoot = getFocusCycleRootAncestor();
Component focusComp = this;
while (focusRoot != null
&& ! (focusRoot.isShowing() && focusRoot.isFocusable()
&& focusRoot.isEnabled()))
{
focusComp = focusRoot;
focusRoot = focusComp.getFocusCycleRootAncestor();
}
if (focusRoot != null)
{
// First try to get the componentBefore from the policy.
FocusTraversalPolicy policy = focusRoot.getFocusTraversalPolicy();
Component nextFocus = policy.getComponentBefore(focusRoot, focusComp);
// If this fails, then ask for the defaultComponent.
if (nextFocus == null)
nextFocus = policy.getDefaultComponent(focusRoot);
// Request focus on this component, if not null.
if (nextFocus != null)
nextFocus.requestFocus();
}
}
Transfers focus to the previous component in the focus traversal
order, as though this were the current focus owner. |
public void transferFocusUpCycle() {
// Find the nearest focus cycle root ancestor that is itself
// focusable, showing and enabled.
Container focusCycleRoot = getFocusCycleRootAncestor();
while (focusCycleRoot != null &&
! (focusCycleRoot.isShowing() && focusCycleRoot.isFocusable()
&& focusCycleRoot.isEnabled()))
{
focusCycleRoot = focusCycleRoot.getFocusCycleRootAncestor();
}
KeyboardFocusManager fm =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
if (focusCycleRoot != null)
{
// If we found a focus cycle root, then we make this the new
// focused component, and make it's focus cycle root the new
// global focus cycle root. If the found root has no focus cycle
// root ancestor itself, then the component will be both the focused
// component and the new global focus cycle root.
Container focusCycleAncestor =
focusCycleRoot.getFocusCycleRootAncestor();
Container globalFocusCycleRoot;
if (focusCycleAncestor == null)
globalFocusCycleRoot = focusCycleRoot;
else
globalFocusCycleRoot = focusCycleAncestor;
fm.setGlobalCurrentFocusCycleRoot(globalFocusCycleRoot);
focusCycleRoot.requestFocus();
}
else
{
// If this component has no applicable focus cycle root, we try
// find the nearest window and set this as the new global focus cycle
// root and the default focus component of this window the new focused
// component.
Container cont;
if (this instanceof Container)
cont = (Container) this;
else
cont = getParent();
while (cont != null && !(cont instanceof Window))
cont = cont.getParent();
if (cont != null)
{
FocusTraversalPolicy policy = cont.getFocusTraversalPolicy();
Component focusComp = policy.getDefaultComponent(cont);
if (focusComp != null)
{
fm.setGlobalCurrentFocusCycleRoot(cont);
focusComp.requestFocus();
}
}
}
}
Transfers focus to the focus cycle root of this component.
However, if this is a Window, the default focus owner in the
window in the current focus cycle is focused instead. |
static Event translateEvent(AWTEvent e) {
Object target = e.getSource ();
Event translated = null;
if (e instanceof InputEvent)
{
InputEvent ie = (InputEvent) e;
long when = ie.getWhen ();
int oldID = 0;
int id = e.getID ();
int oldMods = 0;
int mods = ie.getModifiersEx ();
if ((mods & InputEvent.BUTTON2_DOWN_MASK) != 0)
oldMods |= Event.META_MASK;
else if ((mods & InputEvent.BUTTON3_DOWN_MASK) != 0)
oldMods |= Event.ALT_MASK;
if ((mods & InputEvent.SHIFT_DOWN_MASK) != 0)
oldMods |= Event.SHIFT_MASK;
if ((mods & InputEvent.CTRL_DOWN_MASK) != 0)
oldMods |= Event.CTRL_MASK;
if ((mods & InputEvent.META_DOWN_MASK) != 0)
oldMods |= Event.META_MASK;
if ((mods & InputEvent.ALT_DOWN_MASK) != 0)
oldMods |= Event.ALT_MASK;
if (e instanceof MouseEvent)
{
if (id == MouseEvent.MOUSE_PRESSED)
oldID = Event.MOUSE_DOWN;
else if (id == MouseEvent.MOUSE_RELEASED)
oldID = Event.MOUSE_UP;
else if (id == MouseEvent.MOUSE_MOVED)
oldID = Event.MOUSE_MOVE;
else if (id == MouseEvent.MOUSE_DRAGGED)
oldID = Event.MOUSE_DRAG;
else if (id == MouseEvent.MOUSE_ENTERED)
oldID = Event.MOUSE_ENTER;
else if (id == MouseEvent.MOUSE_EXITED)
oldID = Event.MOUSE_EXIT;
else
// No analogous AWT 1.0 mouse event.
return null;
MouseEvent me = (MouseEvent) e;
translated = new Event (target, when, oldID,
me.getX (), me.getY (), 0, oldMods);
}
else if (e instanceof KeyEvent)
{
if (id == KeyEvent.KEY_PRESSED)
oldID = Event.KEY_PRESS;
else if (e.getID () == KeyEvent.KEY_RELEASED)
oldID = Event.KEY_RELEASE;
else
// No analogous AWT 1.0 key event.
return null;
int oldKey = 0;
int newKey = ((KeyEvent) e).getKeyCode ();
switch (newKey)
{
case KeyEvent.VK_BACK_SPACE:
oldKey = Event.BACK_SPACE;
break;
case KeyEvent.VK_CAPS_LOCK:
oldKey = Event.CAPS_LOCK;
break;
case KeyEvent.VK_DELETE:
oldKey = Event.DELETE;
break;
case KeyEvent.VK_DOWN:
case KeyEvent.VK_KP_DOWN:
oldKey = Event.DOWN;
break;
case KeyEvent.VK_END:
oldKey = Event.END;
break;
case KeyEvent.VK_ENTER:
oldKey = Event.ENTER;
break;
case KeyEvent.VK_ESCAPE:
oldKey = Event.ESCAPE;
break;
case KeyEvent.VK_F1:
oldKey = Event.F1;
break;
case KeyEvent.VK_F10:
oldKey = Event.F10;
break;
case KeyEvent.VK_F11:
oldKey = Event.F11;
break;
case KeyEvent.VK_F12:
oldKey = Event.F12;
break;
case KeyEvent.VK_F2:
oldKey = Event.F2;
break;
case KeyEvent.VK_F3:
oldKey = Event.F3;
break;
case KeyEvent.VK_F4:
oldKey = Event.F4;
break;
case KeyEvent.VK_F5:
oldKey = Event.F5;
break;
case KeyEvent.VK_F6:
oldKey = Event.F6;
break;
case KeyEvent.VK_F7:
oldKey = Event.F7;
break;
case KeyEvent.VK_F8:
oldKey = Event.F8;
break;
case KeyEvent.VK_F9:
oldKey = Event.F9;
break;
case KeyEvent.VK_HOME:
oldKey = Event.HOME;
break;
case KeyEvent.VK_INSERT:
oldKey = Event.INSERT;
break;
case KeyEvent.VK_LEFT:
case KeyEvent.VK_KP_LEFT:
oldKey = Event.LEFT;
break;
case KeyEvent.VK_NUM_LOCK:
oldKey = Event.NUM_LOCK;
break;
case KeyEvent.VK_PAUSE:
oldKey = Event.PAUSE;
break;
case KeyEvent.VK_PAGE_DOWN:
oldKey = Event.PGDN;
break;
case KeyEvent.VK_PAGE_UP:
oldKey = Event.PGUP;
break;
case KeyEvent.VK_PRINTSCREEN:
oldKey = Event.PRINT_SCREEN;
break;
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_KP_RIGHT:
oldKey = Event.RIGHT;
break;
case KeyEvent.VK_SCROLL_LOCK:
oldKey = Event.SCROLL_LOCK;
break;
case KeyEvent.VK_TAB:
oldKey = Event.TAB;
break;
case KeyEvent.VK_UP:
case KeyEvent.VK_KP_UP:
oldKey = Event.UP;
break;
default:
oldKey = (int) ((KeyEvent) e).getKeyChar();
}
translated = new Event (target, when, oldID,
0, 0, oldKey, oldMods);
}
}
else if (e instanceof AdjustmentEvent)
{
AdjustmentEvent ae = (AdjustmentEvent) e;
int type = ae.getAdjustmentType();
int oldType;
if (type == AdjustmentEvent.BLOCK_DECREMENT)
oldType = Event.SCROLL_PAGE_UP;
else if (type == AdjustmentEvent.BLOCK_INCREMENT)
oldType = Event.SCROLL_PAGE_DOWN;
else if (type == AdjustmentEvent.TRACK)
oldType = Event.SCROLL_ABSOLUTE;
else if (type == AdjustmentEvent.UNIT_DECREMENT)
oldType = Event.SCROLL_LINE_UP;
else if (type == AdjustmentEvent.UNIT_INCREMENT)
oldType = Event.SCROLL_LINE_DOWN;
else
oldType = type;
translated = new Event(target, oldType, new Integer(ae.getValue()));
}
else if (e instanceof ActionEvent)
translated = new Event (target, Event.ACTION_EVENT,
((ActionEvent) e).getActionCommand ());
return translated;
}
Translate an AWT 1.1 event (AWTEvent ) into an AWT 1.0
event (Event ). |
public void update(Graphics g) {
// Tests show that the clearing of the background is only done in
// two cases:
// - If the component is lightweight (yes this is in contrast to the spec).
// or
// - If the component is a toplevel container.
if (isLightweight() || getParent() == null)
{
Rectangle clip = g.getClipBounds();
if (clip == null)
g.clearRect(0, 0, width, height);
else
g.clearRect(clip.x, clip.y, clip.width, clip.height);
}
paint(g);
}
Updates this component. This is called in response to
repaint. This method fills the component with the
background color, then sets the foreground color of the specified
graphics context to the foreground color of this component and calls
the paint() method. The coordinates of the graphics are
relative to this component. Subclasses should call either
super.update(g) or paint(g). |
public void validate() {
valid = true;
}
Called to ensure that the layout for this component is valid. This is
usually called on containers. |