Class java.awt.swing.SwingUtilities
java.lang.Object
|
+----java.awt.swing.SwingUtilities
- public class SwingUtilities
- extends Object
- implements SwingConstants
A collection of conveniences for Swing
Method Summary
|
static Rectangle[]
|
computeDifference(Rectangle rectA,
Rectangle rectB)
|
static Rectangle
|
computeIntersection(int x,
int y,
int width,
int height,
Rectangle dest)
|
static int
|
computeStringWidth(FontMetrics fm,
String str)
|
static Rectangle
|
computeUnion(int x,
int y,
int width,
int height,
Rectangle dest)
|
static MouseEvent
|
convertMouseEvent(Component source,
MouseEvent sourceEvent,
Component destination)
Returns a MouseEvent similar to sourceEvent except that its x
and y members have been converted to destination's coordinate
system.
|
static Point
|
convertPoint(Component source,
Point aPoint,
Component destination)
Convert a aPoint in source coordinate system to
destination coordinate system.
|
static Point
|
convertPoint(Component source,
int x,
int y,
Component destination)
Convert the point (x,y) in source coordinate system to
destination coordinate system.
|
static void
|
convertPointFromScreen(Point p,
Component c)
|
static void
|
convertPointToScreen(Point p,
Component c)
|
static Rectangle
|
convertRectangle(Component source,
Rectangle aRectangle,
Component destination)
Convert the rectangle aRectangle in source coordinate system to
destination coordinate system.
|
static Component
|
findFocusOwner(Component c)
Return the child component which has focus, if any.
|
static Accessible
|
getAccessibleAt(Component c,
Point p)
Returns the Accessible child contained at the local coordinate
Point, if one exists.
|
static Accessible
|
getAccessibleChild(Component c,
int i)
Return the nth Accessible child of the object.
|
static int
|
getAccessibleChildrenCount(Component c)
Returns the number of accessible children in the object.
|
static int
|
getAccessibleIndexInParent(Component c)
Get the index of this object in its accessible parent.
|
static AccessibleStateSet
|
getAccessibleStateSet(Component c)
Get the state of this object.
|
static Container
|
getAncestorNamed(String name,
Component comp)
Convience method for searching above comp in the
component hierarchy and returns the first object of name it
finds.
|
static Container
|
getAncestorOfClass(Class c,
Component comp)
Convience method for searching above comp in the
component hierarchy and returns the first object of class c it
finds.
|
static Component
|
getDeepestComponentAt(Component parent,
int x,
int y)
Returns the deepest child Component of parent that is at the location
x, y.
|
static Rectangle
|
getLocalBounds(Component aComponent)
Return the rectangle (0,0,bounds.width,bounds.height) for the component aComponent
|
static JRootPane
|
getRootPane(Component c)
Return the JRootPane ancestor for a Component
Return null if no JRootPane is found.
|
static void
|
invokeAndWait(Runnable obj)
Causes obj to have its run() method called in the dispatch
thread of the EventQueue.
|
static void
|
invokeLater(Runnable obj)
Causes obj to have its run() method called in the dispatch
thread of the EventQueue.
|
static boolean
|
isDescendingFrom(Component a,
Component b)
Return true if a component a descends from a component b
|
static boolean
|
isEventDispatchThread()
|
static boolean
|
isLeftMouseButton(MouseEvent anEvent)
|
static boolean
|
isMiddleMouseButton(MouseEvent anEvent)
|
static boolean
|
isRectangleContainingRectangle(Rectangle a,
Rectangle b)
Return true if a contains b
|
static boolean
|
isRightMouseButton(MouseEvent anEvent)
|
static String
|
layoutCompoundLabel(FontMetrics fm,
String text,
Icon icon,
int verticalAlignment,
int horizontalAlignment,
int verticalTextPosition,
int horizontalTextPosition,
Rectangle viewR,
Rectangle iconR,
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.
|
static void
|
paintComponent(Graphics g,
Component c,
Container p,
int x,
int y,
int w,
int h)
Paint a component c on an abitrary graphics g in the
specified rectangle.
|
static void
|
paintComponent(Graphics g,
Component c,
Container p,
Rectangle r)
|
static void
|
updateComponentTreeUI(Component c)
A simple minded look and feel change: ask each node in the tree
to updateUI(), i.e.
|
static Window
|
windowForComponent(Component aComponent)
Return aComponent 's window
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
isRectangleContainingRectangle
public static final boolean isRectangleContainingRectangle(Rectangle a,
Rectangle b)
- Return true if
a
contains b
getLocalBounds
public static Rectangle getLocalBounds(Component aComponent)
- Return the rectangle (0,0,bounds.width,bounds.height) for the component
aComponent
convertPoint
public static Point convertPoint(Component source,
Point aPoint,
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.
convertPoint
public static Point convertPoint(Component source,
int x,
int y,
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.
convertRectangle
public static Rectangle convertRectangle(Component source,
Rectangle aRectangle,
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.
getAncestorOfClass
public static Container getAncestorOfClass(Class c,
Component comp)
- Convience 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.
getAncestorNamed
public static Container getAncestorNamed(String name,
Component comp)
- Convience 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.
getDeepestComponentAt
public static Component getDeepestComponentAt(Component parent,
int x,
int y)
- Returns the deepest child Component of parent that is at the location
x, y. If parent is not a Container, it is
returned, otherwise this method is messaged again with the child
component at x, y.
convertMouseEvent
public static MouseEvent convertMouseEvent(Component source,
MouseEvent sourceEvent,
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 translateMouseEvent() to translate a mouse event from one component
to another without changing the source.
convertPointToScreen
public static void convertPointToScreen(Point p,
Component c)
convertPointFromScreen
public static void convertPointFromScreen(Point p,
Component c)
windowForComponent
public static Window windowForComponent(Component aComponent)
- Return
aComponent
's window
isDescendingFrom
public static boolean isDescendingFrom(Component a,
Component b)
- Return
true
if a component a
descends from a component b
invokeLater
public static void invokeLater(Runnable obj)
- Causes obj to have its run() method called in the dispatch
thread of the EventQueue. This will happen after all pending events
are processed.
isEventDispatchThread
public static boolean isEventDispatchThread()
- Returns:
- true if the current thread is the event dispatching thread.
invokeAndWait
public static void invokeAndWait(Runnable obj) throws InterruptedException, InvocationTargetException
- Causes obj to have its run() method called in the dispatch
thread of the EventQueue. This will happen after all pending events
are processed. The call blocks until this has happened. This method
will throw and error if called from the event dispatcher thread.
- Throws:
- InterruptedException - if another thread has
interrupted this thread.
- InvocationTargetException - if an exception is thrown when
running obj.
computeIntersection
public static Rectangle computeIntersection(int x,
int y,
int width,
int height,
Rectangle dest)
computeUnion
public static Rectangle computeUnion(int x,
int y,
int width,
int height,
Rectangle dest)
computeDifference
public static Rectangle[] computeDifference(Rectangle rectA,
Rectangle rectB)
isLeftMouseButton
public static boolean isLeftMouseButton(MouseEvent anEvent)
isMiddleMouseButton
public static boolean isMiddleMouseButton(MouseEvent anEvent)
isRightMouseButton
public static boolean isRightMouseButton(MouseEvent anEvent)
computeStringWidth
public static int computeStringWidth(FontMetrics fm,
String str)
layoutCompoundLabel
public static String layoutCompoundLabel(FontMetrics fm,
String text,
Icon icon,
int verticalAlignment,
int horizontalAlignment,
int verticalTextPosition,
int horizontalTextPosition,
Rectangle viewR,
Rectangle iconR,
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.
paintComponent
public static void paintComponent(Graphics g,
Component c,
Container p,
int x,
int y,
int w,
int h)
- Paint a component c on an abitrary graphics g in the
specified rectangle. The component is reparented to a private
container (whose parent becomes p) which prevents c.validate() and
and c.repaint() calls from propogating up the tree. The intermediate
container has no other effect.
paintComponent
public static void paintComponent(Graphics g,
Component c,
Container p,
Rectangle r)
updateComponentTreeUI
public static void updateComponentTreeUI(Component c)
- A simple minded look and feel change: ask each node in the tree
to updateUI(), i.e. to initialize its UI property with the
current look and feel.
getAccessibleIndexInParent
public static int getAccessibleIndexInParent(Component c)
- Get the index of this object in its accessible parent.
- Returns:
- -1 of this object does not have an accessible parent.
Otherwise, the index of the child in its accessible parent.
getAccessibleAt
public static Accessible getAccessibleAt(Component c,
Point p)
- Returns the Accessible child contained at the local coordinate
Point, if one exists.
- Returns:
- the Accessible at the specified location, if it exists
getAccessibleStateSet
public static AccessibleStateSet getAccessibleStateSet(Component c)
- Get the state of this object.
- Returns:
- an instance of AccessibleStateSet containing the current state
set of the object
- See Also:
- AccessibleState
getAccessibleChildrenCount
public static int getAccessibleChildrenCount(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.
- Returns:
- the number of accessible children in the object.
getAccessibleChild
public static Accessible getAccessibleChild(Component c,
int i)
- Return the nth Accessible child of the object.
- Parameters:
i
- zero-based index of child
- Returns:
- the nth Accessible child of the object
findFocusOwner
public static Component findFocusOwner(Component c)
- Return the child component which has focus, if any. The HotJava
SecurityManager forbids applet access to getFocusOwner(), so if the
component is an applet, we check whether a JComponent has focus.
Non-Swing components in an applet on HotJava are out-of-luck,
unfortunately.
getRootPane
public static JRootPane getRootPane(Component c)
- Return the JRootPane ancestor for a Component
Return null if no JRootPane is found.
Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.