FileDocCategorySizeDatePackage
SwingUtilities.javaAPI DocJava SE 5 API69881Fri Aug 26 14:57:58 BST 2005javax.swing

SwingUtilities

public class SwingUtilities extends Object implements SwingConstants
A collection of utility methods for Swing.
version
1.134 06/15/04
author
unknown

Fields Summary
private static boolean
canAccessEventQueue
private static boolean
eventQueueTested
private static final Object
sharedOwnerFrameKey
Constructors Summary
private SwingUtilities()

        throw new Error("SwingUtilities is just a container for static methods");
    
Methods Summary
static java.lang.ObjectappContextGet(java.lang.Object key)

        return AppContext.getAppContext().get(key);
    
static voidappContextPut(java.lang.Object key, java.lang.Object value)

        AppContext.getAppContext().put(key, value);
    
static voidappContextRemove(java.lang.Object key)

        AppContext.getAppContext().remove(key);
    
public static java.awt.RectanglecalculateInnerArea(javax.swing.JComponent c, java.awt.Rectangle r)
Stores the position and size of the inner painting area of the specified component in r and returns r. The position and size specify the bounds of the component, adjusted so as not to include the border area (the insets). This method is useful for classes that implement painting code.

param
c the JComponent in question; if null, this method returns null
param
r the Rectangle instance to be modified; may be null
return
null if the Component is null; otherwise, returns the passed-in rectangle (if non-null) or a new rectangle specifying position and size information
since
1.4

        if (c == null) {
            return null;
        }
        Rectangle rect = r;
        Insets insets = c.getInsets();

        if (rect == null) {
            rect = new Rectangle();
        }

        rect.x = insets.left;
        rect.y = insets.top;
        rect.width = c.getWidth() - insets.left - insets.right;
        rect.height = c.getHeight() - insets.top - insets.bottom;

        return rect;
    
public static java.awt.Rectangle[]computeDifference(java.awt.Rectangle rectA, java.awt.Rectangle rectB)
Convenience returning an array of rect representing the regions within rectA that do not overlap with rectB. If the two Rects do not overlap, returns an empty array

        if (rectB == null || !rectA.intersects(rectB) || isRectangleContainingRectangle(rectB,rectA)) {
            return new Rectangle[0];
        }

        Rectangle t = new Rectangle();
        Rectangle a=null,b=null,c=null,d=null;
        Rectangle result[];
        int rectCount = 0;

        /* rectA contains rectB */
        if (isRectangleContainingRectangle(rectA,rectB)) {
            t.x = rectA.x; t.y = rectA.y; t.width = rectB.x - rectA.x; t.height = rectA.height;
            if(t.width > 0 && t.height > 0) {
                a = new Rectangle(t);
                rectCount++;
            }

            t.x = rectB.x; t.y = rectA.y; t.width = rectB.width; t.height = rectB.y - rectA.y;
            if(t.width > 0 && t.height > 0) {
                b = new Rectangle(t);
                rectCount++;
            }

            t.x = rectB.x; t.y = rectB.y + rectB.height; t.width = rectB.width;
            t.height = rectA.y + rectA.height - (rectB.y + rectB.height);
            if(t.width > 0 && t.height > 0) {
                c = new Rectangle(t);
                rectCount++;
            }

            t.x = rectB.x + rectB.width; t.y = rectA.y; t.width = rectA.x + rectA.width - (rectB.x + rectB.width);
            t.height = rectA.height;
            if(t.width > 0 && t.height > 0) {
                d = new Rectangle(t);
                rectCount++;
            }
        } else {
            /* 1 */
            if (rectB.x <= rectA.x && rectB.y <= rectA.y) {
                if ((rectB.x + rectB.width) > (rectA.x + rectA.width)) {

                    t.x = rectA.x; t.y = rectB.y + rectB.height;
                    t.width = rectA.width; t.height = rectA.y + rectA.height - (rectB.y + rectB.height);
                    if(t.width > 0 && t.height > 0) {
                        a = t;
                        rectCount++;
                    }
                } else if ((rectB.y + rectB.height) > (rectA.y + rectA.height)) {
                    t.setBounds((rectB.x + rectB.width), rectA.y,
                                (rectA.x + rectA.width) - (rectB.x + rectB.width), rectA.height);
                    if(t.width > 0 && t.height > 0) {
                        a = t;
                        rectCount++;
                    }
                } else {
                    t.setBounds((rectB.x + rectB.width), rectA.y,
                                (rectA.x + rectA.width) - (rectB.x + rectB.width),
                                (rectB.y + rectB.height) - rectA.y);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectA.x, (rectB.y + rectB.height), rectA.width,
                                (rectA.y + rectA.height) - (rectB.y + rectB.height));
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }
                }
            } else if (rectB.x <= rectA.x && (rectB.y + rectB.height) >= (rectA.y + rectA.height)) {
                if ((rectB.x + rectB.width) > (rectA.x + rectA.width)) {
                    t.setBounds(rectA.x, rectA.y, rectA.width, rectB.y - rectA.y);
                    if(t.width > 0 && t.height > 0) {
                        a = t;
                        rectCount++;
                    }
                } else {
                    t.setBounds(rectA.x, rectA.y, rectA.width, rectB.y - rectA.y);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }
                    t.setBounds((rectB.x + rectB.width), rectB.y,
                                (rectA.x + rectA.width) - (rectB.x + rectB.width),
                                (rectA.y + rectA.height) - rectB.y);
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }
                }
            } else if (rectB.x <= rectA.x) {
                if ((rectB.x + rectB.width) >= (rectA.x + rectA.width)) {
                    t.setBounds(rectA.x, rectA.y, rectA.width, rectB.y - rectA.y);
                    if(t.width>0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectA.x, (rectB.y + rectB.height), rectA.width,
                                (rectA.y + rectA.height) - (rectB.y + rectB.height));
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }
                } else {
                    t.setBounds(rectA.x, rectA.y, rectA.width, rectB.y - rectA.y);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds((rectB.x + rectB.width), rectB.y,
                                (rectA.x + rectA.width) - (rectB.x + rectB.width),
                                rectB.height);
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectA.x, (rectB.y + rectB.height), rectA.width,
                                (rectA.y + rectA.height) - (rectB.y + rectB.height));
                    if(t.width > 0 && t.height > 0) {
                        c = new Rectangle(t);
                        rectCount++;
                    }
                }
            } else if (rectB.x <= (rectA.x + rectA.width) && (rectB.x + rectB.width) > (rectA.x + rectA.width)) {
                if (rectB.y <= rectA.y && (rectB.y + rectB.height) > (rectA.y + rectA.height)) {
                    t.setBounds(rectA.x, rectA.y, rectB.x - rectA.x, rectA.height);
                    if(t.width > 0 && t.height > 0) {
                        a = t;
                        rectCount++;
                    }
                } else if (rectB.y <= rectA.y) {
                    t.setBounds(rectA.x, rectA.y, rectB.x - rectA.x,
                                (rectB.y + rectB.height) - rectA.y);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectA.x, (rectB.y + rectB.height), rectA.width,
                                (rectA.y + rectA.height) - (rectB.y + rectB.height));
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }
                } else if ((rectB.y + rectB.height) > (rectA.y + rectA.height)) {
                    t.setBounds(rectA.x, rectA.y, rectA.width, rectB.y - rectA.y);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectA.x, rectB.y, rectB.x - rectA.x,
                                (rectA.y + rectA.height) - rectB.y);
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }
                } else {
                    t.setBounds(rectA.x, rectA.y, rectA.width, rectB.y - rectA.y);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectA.x, rectB.y, rectB.x - rectA.x,
                                rectB.height);
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectA.x, (rectB.y + rectB.height), rectA.width,
                                (rectA.y + rectA.height) - (rectB.y + rectB.height));
                    if(t.width > 0 && t.height > 0) {
                        c = new Rectangle(t);
                        rectCount++;
                    }
                }
            } else if (rectB.x >= rectA.x && (rectB.x + rectB.width) <= (rectA.x + rectA.width)) {
                if (rectB.y <= rectA.y && (rectB.y + rectB.height) > (rectA.y + rectA.height)) {
                    t.setBounds(rectA.x, rectA.y, rectB.x - rectA.x, rectA.height);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }
                    t.setBounds((rectB.x + rectB.width), rectA.y,
                                (rectA.x + rectA.width) - (rectB.x + rectB.width), rectA.height);
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }
                } else if (rectB.y <= rectA.y) {
                    t.setBounds(rectA.x, rectA.y, rectB.x - rectA.x, rectA.height);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectB.x, (rectB.y + rectB.height),
                                rectB.width,
                                (rectA.y + rectA.height) - (rectB.y + rectB.height));
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds((rectB.x + rectB.width), rectA.y,
                                (rectA.x + rectA.width) - (rectB.x + rectB.width), rectA.height);
                    if(t.width > 0 && t.height > 0) {
                        c = new Rectangle(t);
                        rectCount++;
                    }
                } else {
                    t.setBounds(rectA.x, rectA.y, rectB.x - rectA.x, rectA.height);
                    if(t.width > 0 && t.height > 0) {
                        a = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds(rectB.x, rectA.y, rectB.width,
                                rectB.y - rectA.y);
                    if(t.width > 0 && t.height > 0) {
                        b = new Rectangle(t);
                        rectCount++;
                    }

                    t.setBounds((rectB.x + rectB.width), rectA.y,
                                (rectA.x + rectA.width) - (rectB.x + rectB.width), rectA.height);
                    if(t.width > 0 && t.height > 0) {
                        c = new Rectangle(t);
                        rectCount++;
                    }
                }
            }
        }

        result = new Rectangle[rectCount];
        rectCount = 0;
        if(a != null)
            result[rectCount++] = a;
        if(b != null)
            result[rectCount++] = b;
        if(c != null)
            result[rectCount++] = c;
        if(d != null)
            result[rectCount++] = d;
        return result;
    
public static java.awt.RectanglecomputeIntersection(int x, int y, int width, int height, java.awt.Rectangle dest)
Convenience to calculate the intersection of two rectangles without allocating a new rectangle. If the two rectangles don't intersect, then the returned rectangle begins at (0,0) and has zero width and height.

param
x the X coordinate of the first rectangle's top-left point
param
y the Y coordinate of the first rectangle's top-left point
param
width the width of the first rectangle
param
height the height of the first rectangle
param
dest the second rectangle
return
dest, modified to specify the intersection

        int x1 = (x > dest.x) ? x : dest.x;
        int x2 = ((x+width) < (dest.x + dest.width)) ? (x+width) : (dest.x + dest.width);
        int y1 = (y > dest.y) ? y : dest.y;
        int y2 = ((y + height) < (dest.y + dest.height) ? (y+height) : (dest.y + dest.height));

        dest.x = x1;
        dest.y = y1;
        dest.width = x2 - x1;
        dest.height = y2 - y1;

	// If rectangles don't intersect, return zero'd intersection.
	if (dest.width < 0 || dest.height < 0) {
	    dest.x = dest.y = dest.width = dest.height = 0;
	}

        return dest;
    
public static intcomputeStringWidth(java.awt.FontMetrics fm, java.lang.String str)
Compute the width of the string using a font with the specified "metrics" (sizes).

param
fm a FontMetrics object to compute with
param
str the String to compute
return
an int containing the string width

        // You can't assume that a string's width is the sum of its
        // characters' widths in Java2D -- it may be smaller due to
        // kerning, etc.
        return SwingUtilities2.stringWidth(null, fm, str);
    
public static java.awt.RectanglecomputeUnion(int x, int y, int width, int height, java.awt.Rectangle dest)
Convenience method that calculates the union of two rectangles without allocating a new rectangle.

param
x the x-coordinate of the first rectangle
param
y the y-coordinate of the first rectangle
param
width the width of the first rectangle
param
height the height of the first rectangle
param
dest the coordinates of the second rectangle; the union of the two rectangles is returned in this rectangle
return
the dest Rectangle

        int x1 = (x < dest.x) ? x : dest.x;
        int x2 = ((x+width) > (dest.x + dest.width)) ? (x+width) : (dest.x + dest.width);
        int y1 = (y < dest.y) ? y : dest.y;
        int y2 = ((y+height) > (dest.y + dest.height)) ? (y+height) : (dest.y + dest.height);

        dest.x = x1;
        dest.y = y1;
        dest.width = (x2 - x1);
        dest.height= (y2 - y1);
        return dest;
    
public static java.awt.event.MouseEventconvertMouseEvent(java.awt.Component source, java.awt.event.MouseEvent sourceEvent, java.awt.Component destination)
Returns a MouseEvent similar to sourceEvent except that its x and y members have been converted to destination's coordinate system. If source is null, sourceEvent x and y members are assumed to be into destination's root component coordinate system. If destination is null, the returned MouseEvent will be in source's coordinate system. sourceEvent will not be changed. A new event is returned. the source field of the returned event will be set to destination if destination is non null use the translateMouseEvent() method to translate a mouse event from one component to another without changing the source.

        Point p = convertPoint(source,new Point(sourceEvent.getX(),
                                                sourceEvent.getY()),
                               destination);
        Component newSource;

        if(destination != null)
            newSource = destination;
        else
            newSource = source;

	MouseEvent newEvent;
	if (sourceEvent instanceof MouseWheelEvent) {
	    MouseWheelEvent sourceWheelEvent = (MouseWheelEvent)sourceEvent;
	    newEvent = new MouseWheelEvent(newSource,
					   sourceWheelEvent.getID(),
					   sourceWheelEvent.getWhen(),
					   sourceWheelEvent.getModifiers(),
					   p.x,p.y,
					   sourceWheelEvent.getClickCount(),
					   sourceWheelEvent.isPopupTrigger(),
					   sourceWheelEvent.getScrollType(),
					   sourceWheelEvent.getScrollAmount(),
					   sourceWheelEvent.getWheelRotation());
	}
	else if (sourceEvent instanceof MenuDragMouseEvent) {
	    MenuDragMouseEvent sourceMenuDragEvent = (MenuDragMouseEvent)sourceEvent;
	    newEvent = new MenuDragMouseEvent(newSource,
					      sourceMenuDragEvent.getID(),
					      sourceMenuDragEvent.getWhen(),
					      sourceMenuDragEvent.getModifiers(),
					      p.x,p.y,
					      sourceMenuDragEvent.getClickCount(),
					      sourceMenuDragEvent.isPopupTrigger(),
					      sourceMenuDragEvent.getPath(),
					      sourceMenuDragEvent.getMenuSelectionManager());
	}
	else {
	    newEvent = new MouseEvent(newSource,
				      sourceEvent.getID(),
				      sourceEvent.getWhen(),
				      sourceEvent.getModifiers(),
				      p.x,p.y,
				      sourceEvent.getClickCount(),
				      sourceEvent.isPopupTrigger());
	}
	return newEvent;
    
public static java.awt.PointconvertPoint(java.awt.Component source, java.awt.Point aPoint, java.awt.Component destination)
Convert a aPoint in source coordinate system to destination coordinate system. If source>is null,aPoint is assumed to be in destination's root component coordinate system. If destinationis null, aPoint will be converted to source's root component coordinate system. If both source and destination are null, return aPoint without any conversion.

        Point p;

        if(source == null && destination == null)
            return aPoint;
        if(source == null) {
            source = getWindowAncestor(destination);
            if(source == null)
                throw new Error("Source component not connected to component tree hierarchy");
        }
        p = new Point(aPoint);
        convertPointToScreen(p,source);
        if(destination == null) {
            destination = getWindowAncestor(source);
            if(destination == null)
                throw new Error("Destination component not connected to component tree hierarchy");
        }
        convertPointFromScreen(p,destination);
        return p;
    
public static java.awt.PointconvertPoint(java.awt.Component source, int x, int y, java.awt.Component destination)
Convert the point (x,y) in source coordinate system to destination coordinate system. If source>is null,(x,y) is assumed to be in destination's root component coordinate system. If destinationis null, (x,y) will be converted to source's root component coordinate system. If both source and destination are null, return (x,y) without any conversion.

        Point point = new Point(x,y);
        return convertPoint(source,point,destination);
    
public static voidconvertPointFromScreen(java.awt.Point p, java.awt.Component c)
Convert a point from a screen coordinates to a component's coordinate system

param
p a Point object (converted to the new coordinate system)
param
c a Component object

        Rectangle b;
        int x,y;

        do {
            if(c instanceof JComponent) {
                x = ((JComponent)c).getX();
                y = ((JComponent)c).getY();
            }  else if(c instanceof java.applet.Applet ||
                       c instanceof java.awt.Window) {
                try {
                    Point pp = c.getLocationOnScreen();
                    x = pp.x;
                    y = pp.y;
                } catch (IllegalComponentStateException icse) {
		    x = c.getX();
		    y = c.getY();
                }
            } else {
		x = c.getX();
		y = c.getY();
            }

            p.x -= x;
            p.y -= y;

            if(c instanceof java.awt.Window || c instanceof java.applet.Applet)
                break;
            c = c.getParent();
        } while(c != null);
    
public static voidconvertPointToScreen(java.awt.Point p, java.awt.Component c)
Convert a point from a component's coordinate system to screen coordinates.

param
p a Point object (converted to the new coordinate system)
param
c a Component object

            Rectangle b;
            int x,y;

            do {
                if(c instanceof JComponent) {
                    x = ((JComponent)c).getX();
                    y = ((JComponent)c).getY();
                } else if(c instanceof java.applet.Applet ||
                          c instanceof java.awt.Window) {
                    try {
                        Point pp = c.getLocationOnScreen();
                        x = pp.x;
                        y = pp.y;
                    } catch (IllegalComponentStateException icse) {
			x = c.getX();
			y = c.getY();
                    }
                } else {
                    x = c.getX();
                    y = c.getY();
                }

                p.x += x;
                p.y += y;

                if(c instanceof java.awt.Window || c instanceof java.applet.Applet)
                    break;
                c = c.getParent();
            } while(c != null);
        
public static java.awt.RectangleconvertRectangle(java.awt.Component source, java.awt.Rectangle aRectangle, java.awt.Component destination)
Convert the rectangle aRectangle in source coordinate system to destination coordinate system. If source>is null,aRectangle is assumed to be in destination's root component coordinate system. If destinationis null, aRectangle will be converted to source's root component coordinate system. If both source and destination are null, return aRectangle without any conversion.

        Point point = new Point(aRectangle.x,aRectangle.y);
        point =  convertPoint(source,point,destination);
        return new Rectangle(point.x,point.y,aRectangle.width,aRectangle.height);
    
static java.awt.PointconvertScreenLocationToParent(java.awt.Container parent, int x, int y)
Converts the location x y to the parents coordinate system, returning the location.

        for (Container p = parent; p != null; p = p.getParent()) {
            if (p instanceof Window) {
                Point point = new Point(x, y);

                SwingUtilities.convertPointFromScreen(point, parent);
                return point;
            }
        }
        throw new Error("convertScreenLocationToParent: no window ancestor");
    
static booleandoesIconReferenceImage(javax.swing.Icon icon, java.awt.Image image)
Returns true if the Icon icon is an instance of ImageIcon, and the image it contains is the same as image.

	Image iconImage = (icon != null && (icon instanceof ImageIcon)) ?
	                   ((ImageIcon)icon).getImage() : null;
	return (iconImage == image);
    
static intfindDisplayedMnemonicIndex(java.lang.String text, int mnemonic)
Returns index of the first occurrence of mnemonic within string text. Matching algorithm is not case-sensitive.

param
text The text to search through, may be null
param
mnemonic The mnemonic to find the character for.
return
index into the string if exists, otherwise -1

        if (text == null || mnemonic == '\0") {
            return -1;
        }

        char uc = Character.toUpperCase((char)mnemonic);
        char lc = Character.toLowerCase((char)mnemonic);

        int uci = text.indexOf(uc);
        int lci = text.indexOf(lc);

        if (uci == -1) {
            return lci;
        } else if(lci == -1) {
            return uci;
        } else {
            return (lci < uci) ? lci : uci;
        }
    
public static java.awt.ComponentfindFocusOwner(java.awt.Component c)
Return the child Component of the specified Component that is the focus owner, if any.

param
c the root of the Component hierarchy to search for the focus owner
return
the focus owner, or null if there is no focus owner, or if the focus owner is not comp, or a descendant of comp
see
java.awt.KeyboardFocusManager#getFocusOwner
deprecated
As of 1.4, replaced by KeyboardFocusManager.getFocusOwner().

	Component focusOwner = KeyboardFocusManager.
	    getCurrentKeyboardFocusManager().getFocusOwner();

	// verify focusOwner is a descendant of c
	for (Component temp = focusOwner; temp != null;
	     temp = (temp instanceof Window) ? null : temp.getParent())
	{
	    if (temp == c) {
		return focusOwner;
	    }
	}

	return null;
    
public static javax.accessibility.AccessiblegetAccessibleAt(java.awt.Component c, java.awt.Point p)
Returns the Accessible child contained at the local coordinate Point, if one exists. Otherwise returns null.

return
the Accessible at the specified location, if it exists; otherwise null

        if (c instanceof Container) {
	    return c.getAccessibleContext().getAccessibleComponent().getAccessibleAt(p);
	} else if (c instanceof Accessible) {
            Accessible a = (Accessible) c;
            if (a != null) {
                AccessibleContext ac = a.getAccessibleContext();
                if (ac != null) {
                    AccessibleComponent acmp;
                    Point location;
                    int nchildren = ac.getAccessibleChildrenCount();
                    for (int i=0; i < nchildren; i++) {
                        a = ac.getAccessibleChild(i);
                        if ((a != null)) {
                            ac = a.getAccessibleContext();
                            if (ac != null) {
                                acmp = ac.getAccessibleComponent();
                                if ((acmp != null) && (acmp.isShowing())) {
                                    location = acmp.getLocation();
                                    Point np = new Point(p.x-location.x,
                                                         p.y-location.y);
                                    if (acmp.contains(np)){
                                        return a;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return (Accessible) c;
        }
        return null;
    
public static javax.accessibility.AccessiblegetAccessibleChild(java.awt.Component c, int i)
Return the nth Accessible child of the object.

Note: as of the Java 2 platform v1.3, it is recommended that developers call Component.AccessibleAWTComponent.getAccessibleIndexInParent() instead of using this method.

param
i zero-based index of child
return
the nth Accessible child of the object

	return c.getAccessibleContext().getAccessibleChild(i);
    
public static intgetAccessibleChildrenCount(java.awt.Component c)
Returns the number of accessible children in the object. If all of the children of this object implement Accessible, than this method should return the number of children of this object.

Note: as of the Java 2 platform v1.3, it is recommended that developers call Component.AccessibleAWTComponent.getAccessibleIndexInParent() instead of using this method.

return
the number of accessible children in the object.

	return c.getAccessibleContext().getAccessibleChildrenCount();
    
public static intgetAccessibleIndexInParent(java.awt.Component c)
Get the index of this object in its accessible parent.

Note: as of the Java 2 platform v1.3, it is recommended that developers call Component.AccessibleAWTComponent.getAccessibleIndexInParent() instead of using this method.

return
-1 of this object does not have an accessible parent. Otherwise, the index of the child in its accessible parent.

	return c.getAccessibleContext().getAccessibleIndexInParent();
    
public static javax.accessibility.AccessibleStateSetgetAccessibleStateSet(java.awt.Component c)
Get the state of this object.

Note: as of the Java 2 platform v1.3, it is recommended that developers call Component.AccessibleAWTComponent.getAccessibleIndexInParent() instead of using this method.

return
an instance of AccessibleStateSet containing the current state set of the object
see
AccessibleState

	return c.getAccessibleContext().getAccessibleStateSet();
    
public static java.awt.ContainergetAncestorNamed(java.lang.String name, java.awt.Component comp)
Convenience method for searching above comp in the component hierarchy and returns the first object of name it finds. Can return null, if name cannot be found.

        if(comp == null || name == null)
            return null;

        Container parent = comp.getParent();
        while(parent != null && !(name.equals(parent.getName())))
            parent = parent.getParent();
        return parent;
    
public static java.awt.ContainergetAncestorOfClass(java.lang.Class c, java.awt.Component comp)
Convenience method for searching above comp in the component hierarchy and returns the first object of class c it finds. Can return null, if a class c cannot be found.

        if(comp == null || c == null)
            return null;

        Container parent = comp.getParent();
        while(parent != null && !(c.isInstance(parent)))
            parent = parent.getParent();
        return parent;
    
private static javax.swing.CellRendererPanegetCellRendererPane(java.awt.Component c, java.awt.Container p)

        Container shell = c.getParent();
        if (shell instanceof CellRendererPane) {
            if (shell.getParent() != p) {
                p.add(shell);
            }
        } else {
            shell = new CellRendererPane();
            shell.add(c);
            p.add(shell);
        }
        return (CellRendererPane)shell;
    
public static java.awt.ComponentgetDeepestComponentAt(java.awt.Component parent, int x, int y)
Returns the deepest visible descendent Component of parent that contains the location x, y. If parent does not contain the specified location, then null is returned. If parent is not a container, or none of parent's visible descendents contain the specified location, parent is returned.

param
parent the root component to begin the search
param
x the x target location
param
y the y target location

        if (!parent.contains(x, y)) {
            return null;
        }
        if (parent instanceof Container) {        
            Component components[] = ((Container)parent).getComponents();
            for (int i = 0 ; i < components.length ; i++) {
                Component comp = components[i];
                if (comp != null && comp.isVisible()) {
                    Point loc = comp.getLocation();
                    if (comp instanceof Container) {
                        comp = getDeepestComponentAt(comp, x - loc.x, y - loc.y);
                    } else {
                        comp = comp.getComponentAt(x - loc.x, y - loc.y);
                    }
                    if (comp != null && comp.isVisible()) {
                        return comp;
                    }
                }
            }
        }
        return parent;
    
public static java.awt.RectanglegetLocalBounds(java.awt.Component aComponent)
Return the rectangle (0,0,bounds.width,bounds.height) for the component aComponent

        Rectangle b = new Rectangle(aComponent.getBounds());
        b.x = b.y = 0;
        return b;
    
public static java.awt.ComponentgetRoot(java.awt.Component c)
Returns the root component for the current component tree.

return
the first ancestor of c that's a Window or the last Applet ancestor

        Component applet = null;
        for(Component p = c; p != null; p = p.getParent()) {
            if (p instanceof Window) {
                return p;
            }
            if (p instanceof Applet) {
                applet = p;
            }
        }
        return applet;
    
public static javax.swing.JRootPanegetRootPane(java.awt.Component c)
If c is a JRootPane descendant return its JRootPane ancestor. If c is a RootPaneContainer then return its JRootPane.

return
the JRootPane for Component c or null.

        if (c instanceof RootPaneContainer) {
            return ((RootPaneContainer)c).getRootPane();
        }
        for( ; c != null; c = c.getParent()) {
            if (c instanceof JRootPane) {
                return (JRootPane)c;
            }
        }
        return null;
    
static java.awt.FramegetSharedOwnerFrame()
Returns a toolkit-private, shared, invisible Frame to be the owner for JDialogs and JWindows created with null owners.

exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless

        Frame sharedOwnerFrame =
            (Frame)SwingUtilities.appContextGet(sharedOwnerFrameKey);
        if (sharedOwnerFrame == null) {
            sharedOwnerFrame = new SharedOwnerFrame();
            SwingUtilities.appContextPut(sharedOwnerFrameKey,
                                         sharedOwnerFrame);
        }
        return sharedOwnerFrame;
    
static java.awt.event.WindowListenergetSharedOwnerFrameShutdownListener()
Returns a SharedOwnerFrame's shutdown listener to dispose the SharedOwnerFrame if it has no more displayable children.

exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless

        Frame sharedOwnerFrame = getSharedOwnerFrame();
	return (WindowListener)sharedOwnerFrame;
    
public static javax.swing.ActionMapgetUIActionMap(javax.swing.JComponent component)
Returns the ActionMap provided by the UI in component component.

This will return null if the UI has not installed an ActionMap.

since
1.3

	ActionMap map = component.getActionMap(false);
	while (map != null) {
	    ActionMap parent = map.getParent();
	    if (parent instanceof UIResource) {
		return parent;
	    }
	    map = parent;
	}
	return null;
    
public static javax.swing.InputMapgetUIInputMap(javax.swing.JComponent component, int condition)
Returns the InputMap provided by the UI for condition condition in component component.

This will return null if the UI has not installed a InputMap of the specified type.

since
1.3

	InputMap map = component.getInputMap(condition, false);
	while (map != null) {
	    InputMap parent = map.getParent();
	    if (parent instanceof UIResource) {
		return parent;
	    }
	    map = parent;
	}
	return null;
    
public static java.awt.WindowgetWindowAncestor(java.awt.Component c)
Returns the first Window ancestor of c, or null if c is not contained inside a Window.

param
c Component to get Window ancestor of.
return
the first Window ancestor of c, or null if c is not contained inside a Window.

        for(Container p = c.getParent(); p != null; p = p.getParent()) {
            if (p instanceof Window) {
                return (Window)p;
            }
        }
        return null;
    
public static voidinvokeAndWait(java.lang.Runnable doRun)
Causes doRun.run() to be executed synchronously on the AWT event dispatching thread. This call blocks until all pending AWT events have been processed and (then) doRun.run() returns. This method should be used when an application thread needs to update the GUI. It should'nt be called from the EventDispatchThread. Here's an example that creates a new application thread that uses invokeAndWait to print a string from the event dispatching thread and then, when that's finished, print a string from the application thread.
final Runnable doHelloWorld = new Runnable() {
public void run() {
System.out.println("Hello World on " + Thread.currentThread());
}
};

Thread appThread = new Thread() {
public void run() {
try {
SwingUtilities.invokeAndWait(doHelloWorld);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("Finished on " + Thread.currentThread());
}
};
appThread.start();
Note that if the Runnable.run method throws an uncaught exception (on the event dispatching thread) it's caught and rethrown, as an InvocationTargetException, on the caller's thread.

Additional documentation and examples for this method can be found in How to Use Threads, in The Java Tutorial.

As of 1.3 this method is just a cover for java.awt.EventQueue.invokeAndWait().

exception
InterruptedException if we're interrupted while waiting for the event dispatching thread to finish excecuting doRun.run()
exception
InvocationTargetException if an exception is thrown while running doRun
see
#invokeLater

	EventQueue.invokeAndWait(doRun);
    
public static voidinvokeLater(java.lang.Runnable doRun)
Causes doRun.run() to be executed asynchronously on the AWT event dispatching thread. This will happen after all pending AWT events have been processed. This method should be used when an application thread needs to update the GUI. In the following example the invokeLater call queues the Runnable object doHelloWorld on the event dispatching thread and then prints a message.
Runnable doHelloWorld = new Runnable() {
public void run() {
System.out.println("Hello World on " + Thread.currentThread());
}
};

SwingUtilities.invokeLater(doHelloWorld);
System.out.println("This might well be displayed before the other message.");
If invokeLater is called from the event dispatching thread -- for example, from a JButton's ActionListener -- the doRun.run() will still be deferred until all pending events have been processed. Note that if the doRun.run() throws an uncaught exception the event dispatching thread will unwind (not the current thread).

Additional documentation and examples for this method can be found in How to Use Threads, in The Java Tutorial.

As of 1.3 this method is just a cover for java.awt.EventQueue.invokeLater().

see
#invokeAndWait

	EventQueue.invokeLater(doRun);
    
public static booleanisDescendingFrom(java.awt.Component a, java.awt.Component b)
Return true if a component a descends from a component b

        if(a == b)
            return true;
        for(Container p = a.getParent();p!=null;p=p.getParent())
            if(p == b)
                return true;
        return false;
    
public static booleanisEventDispatchThread()
Returns true if the current thread is an AWT event dispatching thread.

As of 1.3 this method is just a cover for java.awt.EventQueue.isDispatchThread().

return
true if the current thread is an AWT event dispatching thread

	return EventQueue.isDispatchThread();
    
public static booleanisLeftMouseButton(java.awt.event.MouseEvent anEvent)
Returns true if the mouse event specifies the left mouse button.

param
anEvent a MouseEvent object
return
true if the left mouse button was active

         return ((anEvent.getModifiers() & InputEvent.BUTTON1_MASK) != 0);   
    
static booleanisLeftToRight(java.awt.Component c)

        return c.getComponentOrientation().isLeftToRight();
    
public static booleanisMiddleMouseButton(java.awt.event.MouseEvent anEvent)
Returns true if the mouse event specifies the middle mouse button.

param
anEvent a MouseEvent object
return
true if the middle mouse button was active

        return ((anEvent.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK);
    
public static final booleanisRectangleContainingRectangle(java.awt.Rectangle a, java.awt.Rectangle b)
Return true if a contains b



                
           
        if (b.x >= a.x && (b.x + b.width) <= (a.x + a.width) &&
            b.y >= a.y && (b.y + b.height) <= (a.y + a.height)) {
            return true;
        }
        return false;
    
public static booleanisRightMouseButton(java.awt.event.MouseEvent anEvent)
Returns true if the mouse event specifies the right mouse button.

param
anEvent a MouseEvent object
return
true if the right mouse button was active

        return ((anEvent.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK);
    
static booleanisValidKeyEventForKeyBindings(java.awt.event.KeyEvent e)
Returns true if the e is a valid KeyEvent to use in processing the key bindings associated with JComponents.

        if (e.getID() == KeyEvent.KEY_TYPED) {
            int mod = e.getModifiers();
            if (((mod & ActionEvent.ALT_MASK) != 0) &&
                ((mod & ActionEvent.CTRL_MASK) == 0)) {
                // filter out typed "alt-?" keys, but not those created
                // with AltGr, and not control characters
                return false;
            }
        }
        return true;
    
public static java.lang.StringlayoutCompoundLabel(javax.swing.JComponent c, java.awt.FontMetrics fm, java.lang.String text, javax.swing.Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, java.awt.Rectangle viewR, java.awt.Rectangle iconR, java.awt.Rectangle textR, int textIconGap)
Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string. Locations are computed relative to the viewR rectangle. The JComponents orientation (LEADING/TRAILING) will also be taken into account and translated into LEFT/RIGHT values accordingly.

        boolean orientationIsLeftToRight = true;
        int     hAlign = horizontalAlignment;
        int     hTextPos = horizontalTextPosition;

        if (c != null) {
            if (!(c.getComponentOrientation().isLeftToRight())) {
                orientationIsLeftToRight = false;
            }
        }

        // Translate LEADING/TRAILING values in horizontalAlignment
        // to LEFT/RIGHT values depending on the components orientation
        switch (horizontalAlignment) {
        case LEADING: 
            hAlign = (orientationIsLeftToRight) ? LEFT : RIGHT;
            break;
        case TRAILING: 
            hAlign = (orientationIsLeftToRight) ? RIGHT : LEFT;
            break;
        }

        // Translate LEADING/TRAILING values in horizontalTextPosition
        // to LEFT/RIGHT values depending on the components orientation
        switch (horizontalTextPosition) {
        case LEADING: 
            hTextPos = (orientationIsLeftToRight) ? LEFT : RIGHT;
            break;
        case TRAILING: 
            hTextPos = (orientationIsLeftToRight) ? RIGHT : LEFT;
            break;
        }

        return layoutCompoundLabelImpl(c,
				       fm,
				       text,
				       icon,
				       verticalAlignment,
				       hAlign,
				       verticalTextPosition,
				       hTextPos,
				       viewR,
				       iconR,
				       textR,
				       textIconGap);
    
public static java.lang.StringlayoutCompoundLabel(java.awt.FontMetrics fm, java.lang.String text, javax.swing.Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, java.awt.Rectangle viewR, java.awt.Rectangle iconR, java.awt.Rectangle textR, int textIconGap)
Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string. Locations are computed relative to the viewR rectangle. This layoutCompoundLabel() does not know how to handle LEADING/TRAILING values in horizontalTextPosition (they will default to RIGHT) and in horizontalAlignment (they will default to CENTER). Use the other version of layoutCompoundLabel() instead.

	return layoutCompoundLabelImpl(null, fm, text, icon, 
				       verticalAlignment,
				       horizontalAlignment,
				       verticalTextPosition,
				       horizontalTextPosition,
				       viewR, iconR, textR, textIconGap);
    
private static java.lang.StringlayoutCompoundLabelImpl(javax.swing.JComponent c, java.awt.FontMetrics fm, java.lang.String text, javax.swing.Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, java.awt.Rectangle viewR, java.awt.Rectangle iconR, java.awt.Rectangle textR, int textIconGap)
Compute and return the location of the icons origin, the location of origin of the text baseline, and a possibly clipped version of the compound labels string. Locations are computed relative to the viewR rectangle. This layoutCompoundLabel() does not know how to handle LEADING/TRAILING values in horizontalTextPosition (they will default to RIGHT) and in horizontalAlignment (they will default to CENTER). Use the other version of layoutCompoundLabel() instead.

        /* Initialize the icon bounds rectangle iconR.
         */

        if (icon != null) {
            iconR.width = icon.getIconWidth();
            iconR.height = icon.getIconHeight();
        }
        else {
            iconR.width = iconR.height = 0;
        }

        /* Initialize the text bounds rectangle textR.  If a null
         * or and empty String was specified we substitute "" here
         * and use 0,0,0,0 for textR.
         */

        boolean textIsEmpty = (text == null) || text.equals("");
        int lsb = 0;
        /* Unless both text and icon are non-null, we effectively ignore
         * the value of textIconGap.
         */
        int gap;

	View v = null;
        if (textIsEmpty) {
            textR.width = textR.height = 0;
            text = "";
            gap = 0;
        }
        else {
            int availTextWidth;
            gap = (icon == null) ? 0 : textIconGap;

            if (horizontalTextPosition == CENTER) {
                availTextWidth = viewR.width;
            }
            else {
                availTextWidth = viewR.width - (iconR.width + gap);
            }
	    v = (c != null) ? (View) c.getClientProperty("html") : null;
	    if (v != null) {
		textR.width = Math.min(availTextWidth,
                                       (int) v.getPreferredSpan(View.X_AXIS));
		textR.height = (int) v.getPreferredSpan(View.Y_AXIS);
	    } else {
                textR.width = SwingUtilities2.stringWidth(c, fm, text);
                lsb = SwingUtilities2.getLeftSideBearing(c, fm, text);
                if (lsb < 0) {
                    // If lsb is negative, add it to the width and later
                    // adjust the x location. This gives more space than is
                    // actually needed.
                    // This is done like this for two reasons:
                    // 1. If we set the width to the actual bounds all
                    //    callers would have to account for negative lsb
                    //    (pref size calculations ONLY look at width of
                    //    textR)
                    // 2. You can do a drawString at the returned location
                    //    and the text won't be clipped.
                    textR.width -= lsb;
                }
                if (textR.width > availTextWidth) {
                    text = SwingUtilities2.clipString(c, fm, text,
                                                      availTextWidth);
                    textR.width = SwingUtilities2.stringWidth(c, fm, text);
                }
		textR.height = fm.getHeight();
	    }
        }


        /* Compute textR.x,y given the verticalTextPosition and
         * horizontalTextPosition properties
         */

        if (verticalTextPosition == TOP) {
            if (horizontalTextPosition != CENTER) {
                textR.y = 0;
            }
            else {
                textR.y = -(textR.height + gap);
            }
        }
        else if (verticalTextPosition == CENTER) {
            textR.y = (iconR.height / 2) - (textR.height / 2);
        }
        else { // (verticalTextPosition == BOTTOM)
            if (horizontalTextPosition != CENTER) {
                textR.y = iconR.height - textR.height;
            }
            else {
                textR.y = (iconR.height + gap);
            }
        }

        if (horizontalTextPosition == LEFT) {
            textR.x = -(textR.width + gap);
        }
        else if (horizontalTextPosition == CENTER) {
            textR.x = (iconR.width / 2) - (textR.width / 2);
        }
        else { // (horizontalTextPosition == RIGHT)
            textR.x = (iconR.width + gap);
        }

        /* labelR is the rectangle that contains iconR and textR.
         * Move it to its proper position given the labelAlignment
         * properties.
         *
         * To avoid actually allocating a Rectangle, Rectangle.union
         * has been inlined below.
         */
        int labelR_x = Math.min(iconR.x, textR.x);
        int labelR_width = Math.max(iconR.x + iconR.width,
                                    textR.x + textR.width) - labelR_x;
        int labelR_y = Math.min(iconR.y, textR.y);
        int labelR_height = Math.max(iconR.y + iconR.height,
                                     textR.y + textR.height) - labelR_y;

        int dx, dy;

        if (verticalAlignment == TOP) {
            dy = viewR.y - labelR_y;
        }
        else if (verticalAlignment == CENTER) {
            dy = (viewR.y + (viewR.height / 2)) - (labelR_y + (labelR_height / 2));
        }
        else { // (verticalAlignment == BOTTOM)
            dy = (viewR.y + viewR.height) - (labelR_y + labelR_height);
        }

        if (horizontalAlignment == LEFT) {
            dx = viewR.x - labelR_x;
        }
        else if (horizontalAlignment == RIGHT) {
            dx = (viewR.x + viewR.width) - (labelR_x + labelR_width);
        }
        else { // (horizontalAlignment == CENTER)
            dx = (viewR.x + (viewR.width / 2)) -
                 (labelR_x + (labelR_width / 2));
        }

        /* Translate textR and glypyR by dx,dy.
         */

        textR.x += dx;
        textR.y += dy;

        iconR.x += dx;
        iconR.y += dy;

        if (lsb < 0) {
            // lsb is negative. Shift the x location so that the text is
            // visually drawn at the right location.
            textR.x -= lsb;
        }

        return text;
    
static java.lang.ClassloadSystemClass(java.lang.String className)

	return Class.forName(className, true, Thread.currentThread().
                             getContextClassLoader());
    
public static booleannotifyAction(javax.swing.Action action, javax.swing.KeyStroke ks, java.awt.event.KeyEvent event, java.lang.Object sender, int modifiers)
Invokes actionPerformed on action if action is enabled (and non null). The command for the ActionEvent is determined by:
  1. If the action was registered via registerKeyboardAction, then the command string passed in (null will be used if null was passed in).
  2. Action value with name Action.ACTION_COMMAND_KEY, unless null.
  3. String value of the KeyEvent, unless getKeyChar returns KeyEvent.CHAR_UNDEFINED..
This will return true if action is non-null and actionPerformed is invoked on it.

since
1.3

	if (action == null) {
	    return false;
	}
        if (action instanceof UIAction) {
            if (!((UIAction)action).isEnabled(sender)) {
                return false;
            }
        }
        else if (!action.isEnabled()) {
            return false;
        }
	Object commandO;
	boolean stayNull;

	// Get the command object.
	commandO = action.getValue(Action.ACTION_COMMAND_KEY);
	if (commandO == null && (action instanceof JComponent.ActionStandin)) {
	    // ActionStandin is used for historical reasons to support
	    // registerKeyboardAction with a null value.
	    stayNull = true;
	}
	else {
	    stayNull = false;
	}

	// Convert it to a string.
	String command;

	if (commandO != null) {
	    command = commandO.toString();
	}
	else if (!stayNull && event.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
	    command = String.valueOf(event.getKeyChar());
	}
	else {
	    // Do null for undefined chars, or if registerKeyboardAction
	    // was called with a null.
	    command = null;
	}
	action.actionPerformed(new ActionEvent(sender,
			ActionEvent.ACTION_PERFORMED, command, event.getWhen(),
                        modifiers));
	return true;
    
public static voidpaintComponent(java.awt.Graphics g, java.awt.Component c, java.awt.Container p, int x, int y, int w, int h)
Paints a component c on an arbitrary graphics g in the specified rectangle, specifying the rectangle's upper left corner and size. The component is reparented to a private container (whose parent becomes p) which prevents c.validate() and c.repaint() calls from propagating up the tree. The intermediate container has no other effect.

The component should either descend from JComponent or be another kind of lightweight component. A lightweight component is one whose "lightweight" property (returned by the Component isLightweight method) is true. If the Component is not lightweight, bad things map happen: crashes, exceptions, painting problems...

param
g the Graphics object to draw on
param
c the Component to draw
param
p the intermediate Container
param
x an int specifying the left side of the area draw in, in pixels, measured from the left edge of the graphics context
param
y an int specifying the top of the area to draw in, in pixels measured down from the top edge of the graphics context
param
w an int specifying the width of the area draw in, in pixels
param
h an int specifying the height of the area draw in, in pixels
see
java.awt.Component#isLightweight

        getCellRendererPane(c, p).paintComponent(g, c, p, x, y, w, h,false);
    
public static voidpaintComponent(java.awt.Graphics g, java.awt.Component c, java.awt.Container p, java.awt.Rectangle r)
Paints a component c on an arbitrary graphics g in the specified rectangle, specifying a Rectangle object. The component is reparented to a private container (whose parent becomes p) which prevents c.validate() and c.repaint() calls from propagating up the tree. The intermediate container has no other effect.

The component should either descend from JComponent or be another kind of lightweight component. A lightweight component is one whose "lightweight" property (returned by the Component isLightweight method) is true. If the Component is not lightweight, bad things map happen: crashes, exceptions, painting problems...

param
g the Graphics object to draw on
param
c the Component to draw
param
p the intermediate Container
param
r the Rectangle to draw in
see
java.awt.Component#isLightweight

        paintComponent(g, c, p, r.x, r.y, r.width, r.height);
    
public static booleanprocessKeyBindings(java.awt.event.KeyEvent event)
Process the key bindings for the Component associated with event. This method is only useful if event.getComponent() does not descend from JComponent, or your are not invoking super.processKeyEvent from within your JComponent subclass. JComponent automatically processes bindings from within its processKeyEvent method, hence you rarely need to directly invoke this method.

param
event KeyEvent used to identify which bindings to process, as well as which Component has focus.
return
true if a binding has found and processed
since
1.4

        if (event != null) {
            if (event.isConsumed()) {
                return false;
            }

            Component component = event.getComponent();
            Component last = component;
            boolean pressed = (event.getID() == KeyEvent.KEY_PRESSED);

            if (!isValidKeyEventForKeyBindings(event)) {
                return false;
            }
            // Find the first JComponent in the ancestor hierarchy, and
            // invoke processKeyBindings on it
            while (component != null) {
                if (component instanceof JComponent) {
                    return ((JComponent)component).processKeyBindings(
                                                   event, pressed);
                }
                last = component;
                component = component.getParent();
            }
            // No JComponents, if Window or Applet parent, process
            // WHEN_IN_FOCUSED_WINDOW bindings.
            if ((last instanceof Applet) || (last instanceof Window)) {
                return JComponent.processKeyBindingsForAllComponents(
                                  event, (Container)last, pressed);
            }
        }
        return false;
    
public static voidreplaceUIActionMap(javax.swing.JComponent component, javax.swing.ActionMap uiActionMap)
Convenience method to change the UI ActionMap for component to uiActionMap. If uiActionMap is null, this removes any previously installed UI ActionMap.

since
1.3

        ActionMap map = component.getActionMap((uiActionMap != null));;

	while (map != null) {
	    ActionMap parent = map.getParent();
	    if (parent == null || (parent instanceof UIResource)) {
		map.setParent(uiActionMap);
		return;
	    }
	    map = parent;
	}
    
public static voidreplaceUIInputMap(javax.swing.JComponent component, int type, javax.swing.InputMap uiInputMap)
Convenience method to change the UI InputMap for component to uiInputMap. If uiInputMap is null, this removes any previously installed UI InputMap.

since
1.3

	InputMap map = component.getInputMap(type, (uiInputMap != null));

	while (map != null) {
	    InputMap parent = map.getParent();
	    if (parent == null || (parent instanceof UIResource)) {
		map.setParent(uiInputMap);
		return;
	    }
	    map = parent;
	}
    
public static voidupdateComponentTreeUI(java.awt.Component c)
A simple minded look and feel change: ask each node in the tree to updateUI() -- that is, to initialize its UI property with the current look and feel.

        updateComponentTreeUI0(c);
        c.invalidate();
        c.validate();
        c.repaint();
    
private static voidupdateComponentTreeUI0(java.awt.Component c)

        if (c instanceof JComponent) {
            ((JComponent) c).updateUI();
        }
        Component[] children = null;
        if (c instanceof JMenu) {
            children = ((JMenu)c).getMenuComponents();
        }
        else if (c instanceof Container) {
            children = ((Container)c).getComponents();
        }
        if (children != null) {
            for(int i = 0; i < children.length; i++) {
                updateComponentTreeUI0(children[i]);
            }
        }
    
public static java.awt.WindowwindowForComponent(java.awt.Component c)
Returns the first Window ancestor of c, or null if c is not contained inside a Window.

Note: This method provides the same functionality as getWindowAncestor.

param
c Component to get Window ancestor of.
return
the first Window ancestor of c, or null if c is not contained inside a Window.

        return getWindowAncestor(c);