| Java Doc By Examples | |
| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectjavax.swing.SwingUtilitiesFields inherited from interface javax.swing.SwingConstants | |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST | |
Method Summary | |
static @Deprecated |
|
static Rectangle |
|
static Rectangle[] |
|
static Rectangle |
|
static int |
|
static Rectangle |
|
static MouseEvent |
|
static Point |
|
static Point |
|
static void |
|
static void |
|
static Rectangle |
|
static Accessible |
|
static Accessible |
|
static int |
|
static int |
|
static AccessibleStateSet |
|
static Container |
|
static Container |
|
static Component |
|
static Rectangle |
|
static Component | |
static JRootPane |
|
static ActionMap |
|
static InputMap |
|
static Window |
|
static void |
|
static void |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static String |
|
static String |
|
static boolean |
|
static void |
|
static void |
|
static boolean |
|
static void |
|
static void |
|
static void |
|
static Window |
|
Methods inherited from class java.lang.Object | |
clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait | |
public static @Deprecated Component findFocusOwner(Component c)
Deprecated. As of 1.4, replaced by
KeyboardFocusManager.getFocusOwner().Return the childComponentof the specifiedComponentthat is the focus owner, if any.
- Parameters:
c- the root of theComponenthierarchy to search for the focus owner
- Returns:
- the focus owner, or
nullif there is no focus owner, or if the focus owner is notcomp, or a descendant ofcomp
- See Also:
KeyboardFocusManager.getFocusOwner()
public static Rectangle calculateInnerArea(JComponent c, Rectangle r)
Stores the position and size of the inner painting area of the specified component inrand returnsr. 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.
- Parameters:
c- the JComponent in question; if null, this method returns nullr- the Rectangle instance to be modified; may be null
- Returns:
- 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
1: import jp.ujihara.javax.swing.JPopupMenu; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: import jp.ujihara.javax.swing.plaf.ComponentUI; 4: ... 5: Rectangle r = new Rectangle(); 6: SwingUtilities.calculateInnerArea(c, r); 7: Color saved = g.getColor(); 8: 9: int midAB = r.width / 2 + r.x;
1: import jp.ujihara.javax.swing.JSeparator; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: import jp.ujihara.javax.swing.UIDefaults; 4: ... 5: Rectangle r = new Rectangle(); 6: SwingUtilities.calculateInnerArea(c, r); 7: Color saved = g.getColor(); 8: 9: int midAB = r.width / 2 + r.x;
1: import jp.ujihara.javax.swing.SwingConstants; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: import jp.ujihara.javax.swing.UIDefaults; 4: ... 5: FontMetrics fm = tip.getToolkit().getFontMetrics(tip.getFont()); 6: SwingUtilities.layoutCompoundLabel(tip, fm, tip.getTipText(), null, 7: SwingConstants.CENTER, 8: ... 9: Rectangle vr = new Rectangle(); 10: vr = SwingUtilities.calculateInnerArea(tip, vr); 11: Rectangle ir = new Rectangle(); 12: ... 13: FontMetrics fm = tip.getToolkit().getFontMetrics(tip.getFont()); 14: SwingUtilities.layoutCompoundLabel(tip, fm, tip.getTipText(), null,
1: import jp.ujihara.javax.swing.JComponent; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: import jp.ujihara.javax.swing.UIDefaults; 4: ... 5: 6: SwingUtilities.calculateInnerArea(b, br); 7: ... 8: SwingUtilities.calculateInsetArea(br, b.getMargin(), vr); 9: ... 10: String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f),
1: import jp.ujihara.javax.swing.JLabel; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: import jp.ujihara.javax.swing.UIDefaults; 4: ... 5: 6: vr = SwingUtilities.calculateInnerArea(c, vr); 7: 8: ... 9: { 10: return SwingUtilities.layoutCompoundLabel(label, fontMetrics, text, icon, 11: label.getVerticalAlignment(),
public static Rectangle[] computeDifference(Rectangle rectA, Rectangle rectB)
Convenience returning an array of rect representing the regions withinrectAthat do not overlap withrectB. If the two Rects do not overlap, returns an empty array
public static Rectangle computeIntersection(int x, int y, int width, int height, 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.
- Parameters:
x- the X coordinate of the first rectangle's top-left pointy- the Y coordinate of the first rectangle's top-left pointwidth- the width of the first rectangleheight- the height of the first rectangledest- the second rectangle
- Returns:
dest, modified to specify the intersection
1: Rectangle bounds = originalClip.getBounds(); 2: SwingUtilities.computeIntersection(x, y, width, height, bounds); 3: return bounds; 4: } 5: }
1: import javax.swing.JComponent; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: int imageY = (component.getHeight() - imgHeight) / 2; 6: Rectangle r = SwingUtilities.computeIntersection(imageX, imageY, imgWidth, imgHeight, clipRect); 7: if (r.x == 0 && r.y == 0 && (r.width == 0 || r.height == 0)) { 8: return; 9: }
1: p = new Point(absBounds.x,absBounds.y); 2: SwingUtilities.convertPointFromScreen(p,comboBox); 3: absBounds.x = p.x; 4: ... 5: 6: if ( SwingUtilities.isRectangleContainingRectangle(absBounds,r) ) { 7: r.x = r.x + offset.x; 8: ... 9: Rectangle r2 = new Rectangle(0,-r.height,r.width,r.height); 10: if ( SwingUtilities.isRectangleContainingRectangle(absBounds,r2) ) { 11: r2.x = offset.x; 12: ... 13: if ( inModalDialog ) { 14: SwingUtilities.computeIntersection(absBounds.x,absBounds.y,absBounds.width,absBounds.height,r);
1: import javax.swing.JLabel; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: int imageY = (ph - imgHeight) / 2 + insets.top; 6: Rectangle r = SwingUtilities.computeIntersection(imageX, imageY, imgWidth, imgHeight, clipRect); 7: if (r.x == 0 && r.y == 0 && (r.width == 0 || r.height == 0)) { 8: return; 9: }
public static int computeStringWidth(FontMetrics fm, String str)
Compute the width of the string using a font with the specified "metrics" (sizes).
- Parameters:
fm- a FontMetrics object to compute withstr- the String to compute
- Returns:
- an int containing the string width
1: import javax.swing.JOptionPane; 2: import javax.swing.SwingUtilities; 3: import javax.swing.UIManager; 4: ... 5: frameTitle = getTitle(frameTitle, fm, titleW); 6: xOffset -= SwingUtilities.computeStringWidth(fm, frameTitle); 7: } 8: ... 9: 10: titleLength = SwingUtilities.computeStringWidth(fm, frameTitle); 11: g.drawString(frameTitle, xOffset, yOffset);
1: import javax.swing.JTextArea; 2: import javax.swing.SwingUtilities; 3: import javax.swing.event.ChangeEvent; 4: ... 5: int width = DEFAULT_ICON.getIconWidth(); 6: return Math.max(width, SwingUtilities.computeStringWidth(fontMetrics, userName)); 7: } 8: 9: public int getIconHeight()
1: import javax.swing.SwingConstants; 2: import javax.swing.SwingUtilities; 3: import javax.swing.plaf.LabelUI; 4: ... 5: String clipString = "..."; 6: int totalWidth = SwingUtilities.computeStringWidth(fm, clipString); 7: int nChars; 8: ... 9: rettext = text[0].substring(0, nChars) + clipString; 10: textR.width = SwingUtilities.computeStringWidth(fm, rettext); 11: } 12: ... 13: for (i = 0, c = strs.length; i < c; i++) 14: width = Math.max(width, SwingUtilities.computeStringWidth(fm, strs[i]));
1: String secondLine = title.substring(pos+1); 2: width += Math.max(SwingUtilities.computeStringWidth(metrics, firstLine), 3: ... 4: SwingUtilities.computeStringWidth(metrics, secondLine)); 5: return width; 6: ... 7: textRect.x = textRect.y = iconRect.x = iconRect.y = 0; 8: SwingUtilities.layoutCompoundLabel(tabPane, 9: metrics, title, icon,
1: import javax.swing.JSeparator; 2: import javax.swing.SwingUtilities; 3: import javax.swing.UIManager; 4: ... 5: 6: window = SwingUtilities.getWindowAncestor(this); 7: if (window != null) 8: ... 9: { 10: xOffset -= SwingUtilities.computeStringWidth(fm, theTitle); 11: } 12: ... 13: int titleLength = SwingUtilities.computeStringWidth(fm, theTitle);
public static Rectangle computeUnion(int x, int y, int width, int height, Rectangle dest)
Convenience method that calculates the union of two rectangles without allocating a new rectangle.
- Parameters:
x- the x-coordinate of the first rectangley- the y-coordinate of the first rectanglewidth- the width of the first rectangleheight- the height of the first rectangledest- the coordinates of the second rectangle; the union of the two rectangles is returned in this rectangle
- Returns:
- the
destRectangle
1: rect.setLocation( x, y ); 2: SwingUtilities.computeUnion( rect.x, rect.y, rect.width, rect.height, unionRect ); 3: mSlider.repaint( unionRect.x, unionRect.y, unionRect.width, unionRect.height ); 4: }
1: import java.util.Stack; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: } else { 6: SwingUtilities.computeUnion(rectangle1.x, rectangle1.y, rectangle1.width, rectangle1.height, rectangle); 7: } 8: } 9: }
1: r.setBounds(textRect); 2: r = SwingUtilities.computeUnion(iconRect.x, iconRect.y, iconRect.width, iconRect.height, r); 3: 4: ... 5: 6: SwingUtilities.layoutCompoundLabel( 7: menuItem, fm, text, icon, verticalAlignment, 8: ... 9: { 10: acceleratorRect.width = SwingUtilities.computeStringWidth( fmAccel, acceleratorText ); 11: acceleratorRect.height = fmAccel.getHeight();
public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination)
Returns a MouseEvent similar tosourceEventexcept that its x and y members have been converted todestination's coordinate system. Ifsourceis null,sourceEventx and y members are assumed to be intodestination's root component coordinate system. Ifdestinationisnull, the returned MouseEvent will be insource's coordinate system.sourceEventwill not be changed. A new event is returned. thesourcefield of the returned event will be set todestinationif destination is non null use the translateMouseEvent() method to translate a mouse event from one component to another without changing the source.
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Component source = e.getComponent(); 6: SwingUtilities.convertMouseEvent(source, e, w); 7: return e.getPoint(); 8: } 9: }
1: import java.awt.event.MouseMotionListener; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Component appc = (Component)e.getSource(); 6: MouseEvent ne = SwingUtilities.convertMouseEvent(appc, e, cnt); 7: fireMouseClicked(ne,appc); 8: ... 9: Component appc = (Component)e.getSource(); 10: MouseEvent ne = SwingUtilities.convertMouseEvent(appc, e, cnt); 11: fireMousePressed(ne,appc); 12: ... 13: Component appc = (Component)e.getSource(); 14: MouseEvent ne = SwingUtilities.convertMouseEvent(appc, e, cnt);
public static Point convertPoint(Component source, int x, int y, Component destination)
Convert the point(x,y)insourcecoordinate system todestinationcoordinate system. Ifsource>is null,(x,y)is assumed to be indestination's root component coordinate system. Ifdestinationis null,(x,y)will be converted tosource's root component coordinate system. If bothsourceanddestinationare null, return(x,y)without any conversion.
1: if (layeredPane != null) { 2: Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), layeredPane); 3: ... 4: Point p2 = SwingUtilities.convertPoint(this.getParent(), getLocation(), layeredPane); 5: Dimension size = innerArea.getSize(); 6: ... 7: Dimension minimumSize = getMinimumSize(); 8: Point offset = SwingUtilities.convertPoint(innerArea, 0, 0, layeredPane);
1: Component r=s.getTopLevelAncestor(); 2: Point p=SwingUtilities.convertPoint(s,x,y,r); 3: Rectangle b=r.getBounds(); 4: ... 5: { 6: q=SwingUtilities.convertPoint(d,q.x,q.y,c); 7: again=true; 8:
1: if (enabled && mousePressed) { 2: Point p = SwingUtilities.convertPoint((JComponent) e.getSource(), e.getPoint(), component); 3: if (dragStarted || enableInsideDrag || !component.contains(p)) { 4: ... 5: else if (!checkParentContains( 6: SwingUtilities.convertPoint((JComponent) e.getSource(), e.getPoint(), component.getParent()))) { 7: restoreComponentOrder(); 8: ... 9: 10: Point p2 = SwingUtilities.convertPoint(component, p, parent); 11: int toIndex = getMoveComponentIndex(p2); 12: ... 13: fromDimension = fromComponent.getHeight(); 14: toPos = (int) SwingUtilities.convertPoint(parent, p2, getComponent(parent, toIndex)).getY();
1: if (paintTabAreaShadow) { 2: Rectangle bounds = SwingUtilities.calculateInnerArea(componentsPanel, new Rectangle()); 3: 4: ... 5: private int paintHighlightedTabShadow(Graphics g, Direction tabOrientation, Rectangle contentPanelBounds) { 6: Point p = SwingUtilities.convertPoint(highlightedTab.getParent(), highlightedTab.getLocation(), component); 7: 8: ... 9: Rectangle bounds = tabAreaComponentsPanel.isVisible() ? 10: SwingUtilities.convertRectangle(tabAreaComponentsPanel.getParent(), 11: tabAreaComponentsPanel.getBounds(), 12: ... 13: 0); 14: Point tabsPos = SwingUtilities.convertPoint(tabBox, 0, 0, component);
1: import jp.ujihara.javax.accessibility.Accessible; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: 4: ... 5: candidate = 6: SwingUtilities.getDeepestComponentAt(parent, p.x, p.y); 7: if (candidate == null || (candidate.eventMask & me.getID()) == 0) 8: ... 9: candidate = null; 10: p = SwingUtilities.convertPoint(parent, p.x, p.y, parent.parent); 11: parent = parent.parent; 12: ... 13: { 14: if (SwingUtilities.isDescendingFrom(lastComponentEntered, nativeContainer))
public static Point convertPoint(Component source, Point aPoint, Component destination)
Convert aaPointinsourcecoordinate system todestinationcoordinate system. Ifsource>is null,aPointis assumed to be indestination's root component coordinate system. Ifdestinationis null,aPointwill be converted tosource's root component coordinate system. If bothsourceanddestinationare null, returnaPointwithout any conversion.
1: Point containerPoint = 2: SwingUtilities.convertPoint(this, pt,contentPane); 3: 4: ... 5: Component component = SwingUtilities.getDeepestComponentAt( 6: contentPane, 7: ... 8: 9: Point componentPoint = SwingUtilities.convertPoint( 10: this,
1: public void hierarchyChanged(final HierarchyEvent e) { 2: SwingUtilities.invokeLater(new Runnable() { 3: public void run() { 4: ... 5: else if (!((Component) event.getSource()).contains(event.getPoint())) { 6: final Point p = SwingUtilities.convertPoint((Component) event.getSource(), event.getPoint(), top); 7: if (!top.contains(p.x, p.y)) { 8: ... 9: else if (top instanceof Container) { 10: SwingUtilities.invokeLater(new Runnable() { 11: public void run() { 12: ... 13: if (c != null) { 14: Point p2 = SwingUtilities.convertPoint(top, p, c);
1: Point p = e.getPoint(); 2: Point p2 = SwingUtilities.convertPoint(header, p, editorComponent); 3: ... 4: dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, p2.x, p2.y); 5: } 6: ... 7: 8: MouseEvent e2 = SwingUtilities.convertMouseEvent(header, e, dispatchComponent); 9: dispatchComponent.dispatchEvent(e2); 10: ... 11: { 12: if (!SwingUtilities.isLeftMouseButton(e))
public static void convertPointFromScreen(Point p, Component c)
Convert a point from a screen coordinates to a component's coordinate system
- Parameters:
p- a Point object (converted to the new coordinate system)c- a Component object
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Point p = (Point) e.getPoint().clone(); 6: SwingUtilities.convertPointToScreen(p, c); 7: ... 8: SwingUtilities.convertPointFromScreen(p, glassPane); 9: glassPane.setPoint(p);
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Point p = (Point) e.getPoint().clone(); 6: SwingUtilities.convertPointToScreen(p, c); 7: ... 8: SwingUtilities.convertPointFromScreen(p, glassPane); 9: 10: ... 11: Point p = (Point) e.getPoint().clone(); 12: SwingUtilities.convertPointToScreen(p, c);
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Point p = (Point) e.getPoint().clone(); 6: SwingUtilities.convertPointToScreen(p, c); 7: ... 8: SwingUtilities.convertPointFromScreen(p, glassPane); 9: 10: ... 11: Point p = (Point) e.getPoint().clone(); 12: SwingUtilities.convertPointToScreen(p, c);
public static void convertPointToScreen(Point p, Component c)
Convert a point from a component's coordinate system to screen coordinates.
- Parameters:
p- a Point object (converted to the new coordinate system)c- a Component object
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Point p = (Point) e.getPoint().clone(); 6: SwingUtilities.convertPointToScreen(p, c); 7: ... 8: SwingUtilities.convertPointFromScreen(p, glassPane); 9: glassPane.setPoint(p);
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Point p = (Point) e.getPoint().clone(); 6: SwingUtilities.convertPointToScreen(p, c); 7: ... 8: SwingUtilities.convertPointFromScreen(p, glassPane); 9: 10: ... 11: Point p = (Point) e.getPoint().clone(); 12: SwingUtilities.convertPointToScreen(p, c);
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Point p = (Point) e.getPoint().clone(); 6: SwingUtilities.convertPointToScreen(p, c); 7: ... 8: SwingUtilities.convertPointFromScreen(p, glassPane); 9: 10: ... 11: Point p = (Point) e.getPoint().clone(); 12: SwingUtilities.convertPointToScreen(p, c);
1: Point ps= new Point(xs, ys); 2: SwingUtilities.convertPointToScreen(ps, (JComponent)_evt.getSource()); 3: if (ps.x + mnSize.width > scSize.width) 4: xmn -= mnSize.width; 5: if (ps.y + mnSize.height > scSize.height)
1: import javax.swing.RootPaneContainer; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: Point location = contentPane.getLocation(); 6: SwingUtilities.convertPointToScreen(location, contentPane); 7: Dimension size = contentPane.getSize(); 8: Rectangle rectangle = new Rectangle(location.x, location.y, size.width, size.height); 9:
public static Rectangle convertRectangle(Component source, Rectangle aRectangle, Component destination)
Convert the rectangleaRectangleinsourcecoordinate system todestinationcoordinate system. Ifsource>is null,aRectangleis assumed to be indestination's root component coordinate system. Ifdestinationis null,aRectanglewill be converted tosource's root component coordinate system. If bothsourceanddestinationare null, returnaRectanglewithout any conversion.
1: JComponent invoker=getTopComponent 2: (SwingUtilities.getDeepestComponentAt 3: (KorteMain.getInstance(),x,y)); 4: ... 5: Rectangle rn =new Rectangle(_evt.getX(),_evt.getY(),0,0); 6: rn=SwingUtilities.convertRectangle(kmi,rn,mp); 7: kmi.setHighlightArea(rn); 8: ... 9: current_=getTopComponent 10: (SwingUtilities.getDeepestComponentAt 11: (KorteMain.getInstance(),x,y)); 12: ... 13: position_=dt.getPosition(current_); 14: origin_=SwingUtilities.convertPoint
1: import javax.swing.JComponent; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: { 6: return SwingUtilities.convertPoint(component, 7: ReferenceConstants.ORIGIN, 8: ... 9: Rectangle visibleRect = viewer.getVisibleRect(); 10: visibleRect = SwingUtilities.convertRectangle(viewer, visibleRect, referencePanel); 11: ViewPoint globalAll = new ViewPoint(location);
public static Accessible getAccessibleAt(Component c, Point p)
Returns theAccessiblechild contained at the local coordinatePoint, if one exists. Otherwise returnsnull.
- Returns:
- the
Accessibleat the specified location, if it exists; otherwisenull
public static Accessible getAccessibleChild(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.
- Parameters:
i- zero-based index of child
- Returns:
- the nth Accessible child of the object
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. Note: as of the Java 2 platform v1.3, it is recommended that developers call Component.AccessibleAWTComponent.getAccessibleIndexInParent() instead of using this method.
- Returns:
- the number of accessible children in the object.
public static int getAccessibleIndexInParent(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.
- Returns:
- -1 of this object does not have an accessible parent. Otherwise, the index of the child in its accessible parent.
public static AccessibleStateSet getAccessibleStateSet(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.
- Returns:
- an instance of AccessibleStateSet containing the current state set of the object
- See Also:
AccessibleState
public static Container getAncestorNamed(String name, Component comp)
Convenience method for searching abovecompin the component hierarchy and returns the first object ofnameit finds. Can return null, ifnamecannot be found.
public static Container getAncestorOfClass(Class> c, Component comp)
Convenience method for searching abovecompin the component hierarchy and returns the first object of classcit finds. Can return null, if a classccannot be found.
1: final JInternalFrame jif = (JInternalFrame) 2: SwingUtilities.getAncestorOfClass(JInternalFrame.class, FindView.this); 3: jif.dispose(); 4: } 5: });
1: import javax.swing.JScrollPane; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: { 6: Container refPanel = SwingUtilities.getAncestorOfClass(ReferencePanel.class, parent); 7: if (refPanel != null) 8: ... 9: { 10: Container refPanel = SwingUtilities.getAncestorOfClass(ReferencePanel.class, parent); 11: if (refPanel != null)
1: final JInternalFrame jif = (JInternalFrame) 2: SwingUtilities.getAncestorOfClass(JInternalFrame.class, ParamListView.this); 3: 4: ... 5: { 6: SwingUtilities.invokeLater(new Runnable() 7: { 8: ... 9: final JInternalFrame jif = (JInternalFrame) 10: SwingUtilities.getAncestorOfClass(JInternalFrame.class, ParamListView.this); 11: jif.dispose();
public static Component getDeepestComponentAt(Component parent, int x, int y)
Returns the deepest visible descendent Component ofparentthat contains the locationx,y. Ifparentdoes not contain the specified location, thennullis returned. Ifparentis not a container, or none ofparent's visible descendents contain the specified location,parentis returned.
- Parameters:
parent- the root component to begin the searchx- the x target locationy- the y target location
1: import jp.ujihara.javax.accessibility.Accessible; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: 4: ... 5: candidate = 6: SwingUtilities.getDeepestComponentAt(parent, p.x, p.y); 7: if (candidate == null || (candidate.eventMask & me.getID()) == 0) 8: ... 9: candidate = null; 10: p = SwingUtilities.convertPoint(parent, p.x, p.y, parent.parent); 11: parent = parent.parent; 12: ... 13: { 14: if (SwingUtilities.isDescendingFrom(lastComponentEntered, nativeContainer))
public static Rectangle getLocalBounds(Component aComponent)
Return the rectangle (0,0,bounds.width,bounds.height) for the componentaComponent
public static Component getRoot(Component c)
Returns the root component for the current component tree.
- Returns:
- the first ancestor of c that's a Window or the last Applet ancestor
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: if (source instanceof Component) { 6: result = SwingUtilities.getRoot((Component)source); 7: } else if (source instanceof MenuComponent) { 8: ... 9: if (mParent instanceof Component) { 10: result = SwingUtilities.getRoot((Component)mParent); 11: }
1: import javax.swing.Icon; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: { 6: Component root = SwingUtilities.getRoot(c); 7: if (root instanceof Window) 8: { 9: ((Window) root).dispose();
1: import javax.swing.PopupFactory; 2: import javax.swing.SwingUtilities; 3: import javax.swing.event.DocumentEvent; 4: ... 5: owner.addComponentListener(this); 6: Component root = SwingUtilities.getRoot(getDisplayOwner()); 7: if (root != null) 8: ... 9: System.out.print("owner " + p + " to "); 10: SwingUtilities.convertPointToScreen(p, getDisplayOwner()); 11: System.out.print(p); 12: ... 13: owner.removeComponentListener(this); 14: Component root = SwingUtilities.getRoot(getDisplayOwner());
1: import javax.swing.JScrollPane; 2: import javax.swing.SwingUtilities; 3: import javax.swing.filechooser.FileFilter; 4: ... 5: final Component parent = 6: SwingUtilities.getRoot(ParseTreeInfoPanel.this); 7: fc.showDialog(parent, "Open"); 8: ... 9: final Component parent = 10: SwingUtilities.getRoot(ParseTreeInfoPanel.this); 11: openFile(mCurrentFile, parent); 12: ... 13: }; 14: SwingUtilities.invokeLater(showError);
public static JRootPane getRootPane(Component c)
If c is a JRootPane descendant return its JRootPane ancestor. If c is a RootPaneContainer then return its JRootPane.
- Returns:
- the JRootPane for Component c or null.
1: findDialog = new JDialog((Frame) 2: SwingUtilities. 3: getRootPane(szap).getParent(),"Find"); 4: ... 5: findDialog.setLocationRelativeTo( 6: SwingUtilities.getRootPane(szap).getParent()); 7: FindPanel fp = new FindPanel(szap,szap.getController()); 8: findDialog.addWindowListener(new FindWindowListener()); 9: findDialog.getContentPane().add(fp);
public static ActionMap getUIActionMap(JComponent component)
Returns the ActionMap provided by the UI in componentcomponent. This will return null if the UI has not installed an ActionMap.
- Since:
- 1.3
public static InputMap getUIInputMap(JComponent component, int condition)
Returns the InputMap provided by the UI for conditionconditionin componentcomponent. This will return null if the UI has not installed a InputMap of the specified type.
- Since:
- 1.3
public static Window getWindowAncestor(Component c)
Returns the firstWindowancestor ofc, or null ifcis not contained inside aWindow.
- Parameters:
c-Componentto getWindowancestor of.
- Returns:
- the first
Windowancestor ofc, or null ifcis not contained inside aWindow.
1: import javax.swing.JPanel; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: public JFrame getFrame(){ 6: return (JFrame)SwingUtilities.getWindowAncestor(this); 7: } 8: 9: public Point getAppletLocationOnScreen(){
1: import javax.swing.JProgressBar; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: setSize(getSize().width * 2, getSize().height); 6: setLocationRelativeTo(SwingUtilities.getWindowAncestor(this)); 7: 8: ... 9: { 10: SwingUtilities.invokeLater(new Runnable() 11: { 12: ... 13: { 14: SwingUtilities.invokeLater(new Runnable()
1: import javax.swing.JPanel; 2: import javax.swing.SwingUtilities; 3: import javax.swing.event.ChangeEvent; 4: ... 5: JFileChooser chooser = getResinHomeChooser(); 6: int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), 7: "Choose Resin Home"); 8: 9: if (ret == JFileChooser.APPROVE_OPTION)
1: import javax.swing.PopupFactory; 2: import javax.swing.SwingUtilities; 3: import javax.swing.ToolTipManager; 4: ... 5: 6: Window ttip = SwingUtilities.getWindowAncestor(getParent()); 7: if ( ttip == null || !ttip.isVisible() ) { 8: ... 9: c, JCustomTooltip.this, point.x, point.y); 10: Window w = SwingUtilities.getWindowAncestor(JCustomTooltip.this); 11: w.addMouseListener(this); 12: ... 13: { 14: Window w = SwingUtilities.getWindowAncestor(JCustomTooltip.this);
public static void invokeAndWait(Runnable doRun) throws InterruptedException, InvocationTargetException
CausesdoRun.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 theEventDispatchThread. Here's an example that creates a new application thread that usesinvokeAndWaitto 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 theRunnable.runmethod throws an uncaught exception (on the event dispatching thread) it's caught and rethrown, as anInvocationTargetException, 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 forjava.awt.EventQueue.invokeAndWait().
- Throws:
InterruptedException- if we're interrupted while waiting for the event dispatching thread to finish excecutingdoRun.run()InvocationTargetException- if an exception is thrown while runningdoRun
- See Also:
invokeLater(Runnable)
1: 2: import javax.swing.SwingUtilities; 3: import javax.swing.JScrollPane; 4: ... 5: }; 6: SwingUtilities.invokeLater(finisher); 7: } 8: ... 9: try { 10: SwingUtilities.invokeAndWait(errorDisplay); 11: } catch (Throwable e) {
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: try { 6: SwingUtilities.invokeAndWait(adapter); 7: } catch (InterruptedException ex) { 8: throw new RuntimeException(ex); 9: } catch (InvocationTargetException ex) {
1: import javax.swing.Action; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: { 6: SwingUtilities.invokeAndWait(doFinished); 7: } 8: catch (InterruptedException ex) 9: {
1: ErrorDisplay ed = new ErrorDisplay(errObjs); 2: if (SwingUtilities.isEventDispatchThread()) { 3: ed.run(); 4: ... 5: try { 6: SwingUtilities.invokeAndWait(ed); 7: } catch (Exception e) { 8: ... 9: if (importController.importData(conflictImport)) { 10: SwingUtilities.invokeLater(finisher); 11: }
public static void invokeLater(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 theinvokeLatercall queues theRunnableobjectdoHelloWorldon 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 forjava.awt.EventQueue.invokeLater().
- See Also:
invokeAndWait(Runnable)
1: import javax.swing.UIManager; 2: import javax.swing.SwingUtilities; 3: import java.net.InetAddress; 4: ... 5: }; 6: SwingUtilities.invokeLater(resetIt); 7: } 8: ... 9: }; 10: SwingUtilities.invokeLater(addIt); 11: } 12: ... 13: }; 14: SwingUtilities.invokeLater(removeIt);
1: 2: SwingUtilities.invokeLater(new disposeIt(this)); 3: 4: ... 5: }; 6: SwingUtilities.invokeLater(resetIt); 7: } 8: ... 9: }; 10: SwingUtilities.invokeLater(addIt); 11: } 12: ... 13: }; 14: SwingUtilities.invokeLater(removeIt);
1: arrayDirectories.setFid(fid); 2: SwingUtilities.invokeLater(arrayDirectories); 3: } 4: ... 5: arraySortFiles[i].setFid(fid); 6: SwingUtilities.invokeLater(arraySortFiles[i]); 7: } 8: ... 9: arrayFiles.setFid(fid); 10: SwingUtilities.invokeLater(arrayFiles); 11: }
1: public void run() { 2: ld = new JDialog((JFrame)SwingUtilities.getAncestorOfClass(ApolloFrame.class,szap),"Loading sequence"); 3: ... 4: ld.setLocationRelativeTo(SwingUtilities.getRootPane(szap).getParent()); 5: JPanel p = new JPanel(); 6: ... 7: if (evt.getType() == LazyLoadEvent.BEFORE_LOAD) { 8: if (!SwingUtilities.isEventDispatchThread()) { 9: ... 10: SwingUtilities.invokeLater(beforeLazyLoad);
public static boolean isDescendingFrom(Component a, Component b)
Returntrueif a componentadescends from a componentb
public static boolean isEventDispatchThread()
Returns true if the current thread is an AWT event dispatching thread. As of 1.3 this method is just a cover forjava.awt.EventQueue.isDispatchThread().
- Returns:
- true if the current thread is an AWT event dispatching thread
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: if (! isNotifyOnEDT() 6: || SwingUtilities.isEventDispatchThread()) { 7: super.firePropertyChange(evt); 8: ... 9: } else { 10: SwingUtilities.invokeLater( 11: new Runnable() {
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: if (! isNotifyOnEDT() 6: || SwingUtilities.isEventDispatchThread()) { 7: super.firePropertyChange(evt); 8: ... 9: } else { 10: SwingUtilities.invokeLater( 11: new Runnable() {
1: import javax.swing.ListModel; 2: import javax.swing.SwingUtilities; 3: import javax.swing.event.ListDataEvent; 4: ... 5: { 6: assert SwingUtilities.isEventDispatchThread(); 7: ListDataEvent evt = 8: new ListDataEvent(me, eventType, index0, index1); 9: for (int i = 0; i < ldls.length; i++)
public static boolean isLeftMouseButton(MouseEvent anEvent)
Returns true if the mouse event specifies the left mouse button.
- Parameters:
anEvent- a MouseEvent object
- Returns:
- true if the left mouse button was active
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: if ( item instanceof NodeItem && 6: SwingUtilities.isLeftMouseButton(e)) 7: { 8: final FocusManager focusManager = registry.getFocusManager(); 9: final FocusSet focusSet = focusManager.getFocusSet(focusKey);
1: import javax.swing.Icon; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: private boolean isOnlyLeftMouseButton(MouseEvent e) { 6: return SwingUtilities.isLeftMouseButton(e) && 7: ... 8: !SwingUtilities.isRightMouseButton(e); 9: }
1: 2: import javax.swing.SwingUtilities; 3: import javax.swing.event.MouseInputListener; 4: ... 5: if (table.isPointSelected(e.getPoint()) && 6: SwingUtilities.isLeftMouseButton(e) ) { 7: dndArmed = true; 8: e.consume(); 9: delegate.mousePressed(e);
public static boolean isMiddleMouseButton(MouseEvent anEvent)
Returns true if the mouse event specifies the middle mouse button.
- Parameters:
anEvent- a MouseEvent object
- Returns:
- true if the middle mouse button was active
public static final boolean isRectangleContainingRectangle(Rectangle a, Rectangle b)
Return true ifacontainsb
public static boolean isRightMouseButton(MouseEvent anEvent)
Returns true if the mouse event specifies the right mouse button.
- Parameters:
anEvent- a MouseEvent object
- Returns:
- true if the right mouse button was active
1: 2: import javax.swing.SwingUtilities; 3: 4: ... 5: protected boolean isPopupTrigger(MouseEvent e) { 6: return SwingUtilities.isRightMouseButton(e) && !e.isShiftDown(); 7: } 8: public void mousePressed(MouseEvent e) { 9: if ( !isPopupTrigger(e) )
1: import javax.swing.Icon; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: try { 6: double zoomFactor = SwingUtilities.isRightMouseButton(e) 7: ? (1 / ZOOM_IN_FACTOR) : ZOOM_IN_FACTOR; 8: ... 9: try { 10: if (SwingUtilities.isLeftMouseButton(e)) { 11: super.mousePressed(e);
1: { 2: mouseEvent(e.getPoint(), e.isControlDown(), SwingUtilities.isRightMouseButton(e)); 3: } 4: } 5: );
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. 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.
public static String layoutCompoundLabel(JComponent c, 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. The JComponents orientation (LEADING/TRAILING) will also be taken into account and translated into LEFT/RIGHT values accordingly.
public static boolean notifyAction(Action action, KeyStroke ks, KeyEvent event, Object sender, int modifiers)
InvokesactionPerformedonactionifactionis enabled (and non null). The command for the ActionEvent is determined by:This will return true if
- If the action was registered via
registerKeyboardAction, then the command string passed in (null will be used if null was passed in).- Action value with name Action.ACTION_COMMAND_KEY, unless null.
- String value of the KeyEvent, unless
getKeyCharreturns KeyEvent.CHAR_UNDEFINED..actionis non-null and actionPerformed is invoked on it.
- Since:
- 1.3
public static void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)
Paints a componentcon an arbitrary graphicsgin 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 preventsc.validate()andc.repaint()calls from propagating up the tree. The intermediate container has no other effect. The component should either descend fromJComponentor be another kind of lightweight component. A lightweight component is one whose "lightweight" property (returned by theComponentisLightweightmethod) is true. If the Component is not lightweight, bad things map happen: crashes, exceptions, painting problems...
- Parameters:
g- theGraphicsobject to draw onc- theComponentto drawp- the intermediateContainerx- an int specifying the left side of the area draw in, in pixels, measured from the left edge of the graphics contexty- an int specifying the top of the area to draw in, in pixels measured down from the top edge of the graphics contextw- an int specifying the width of the area draw in, in pixelsh- an int specifying the height of the area draw in, in pixels
- See Also:
Component.isLightweight()
public static void paintComponent(Graphics g, Component c, Container p, Rectangle r)
Paints a componentcon an arbitrary graphicsgin the specified rectangle, specifying a Rectangle object. The component is reparented to a private container (whose parent becomesp) which preventsc.validate()andc.repaint()calls from propagating up the tree. The intermediate container has no other effect. The component should either descend fromJComponentor be another kind of lightweight component. A lightweight component is one whose "lightweight" property (returned by theComponentisLightweightmethod) is true. If the Component is not lightweight, bad things map happen: crashes, exceptions, painting problems...
- Parameters:
g- theGraphicsobject to draw onc- theComponentto drawp- the intermediateContainerr- theRectangleto draw in
- See Also:
Component.isLightweight()
1: import javax.swing.JTree; 2: import javax.swing.SwingUtilities; 3: import javax.swing.event.MouseInputAdapter; 4: ... 5: c.setFont(tree.getFont()); 6: Rectangle paintBounds = SwingUtilities.convertRectangle(tree, 7: bounds, this); 8: ... 9: SwingUtilities.paintComponent(g, renderer, this, paintBounds); 10: if (selected)
1: import javax.swing.SwingConstants; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: 6: SwingUtilities.paintComponent(g2d, component, this, rectangle); 7: 8: ... 9: } else 10: SwingUtilities.paintComponent(g2d, component, this, rectangle);
1: import javax.swing.SwingConstants; 2: import javax.swing.SwingUtilities; 3: public class HexagonalTilesPanel extends JPanel implements Scrollable { 4: ... 5: } 6: SwingUtilities.paintComponent(g2d, component, this, polygonBounds); 7: if ((component instanceof JComponent) && wasDoubleBuffered) { 8: ((JComponent)component).setDoubleBuffered(true); 9: }
1: import jp.ujihara.javax.swing.SwingConstants; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: import jp.ujihara.javax.swing.UIDefaults; 4: ... 5: title.setText(getTitle(frame.getTitle(), fm, title.getBounds().width)); 6: SwingUtilities.paintComponent(g, title, null, title.getBounds()); 7: g.setColor(saved); 8: ... 9: Rectangle tr = new Rectangle(); 10: String value = SwingUtilities.layoutCompoundLabel(this, fm, text, null, 11: SwingConstants.CENTER,
1: import jp.ujihara.javax.swing.JSlider; 2: import jp.ujihara.javax.swing.SwingUtilities; 3: import jp.ujihara.javax.swing.Timer; 4: ... 5: insetCache = slider.getInsets(); 6: focusRect = SwingUtilities.calculateInnerArea(slider, focusRect); 7: 8: ... 9: label.setBounds(xpos, ypos, w, h); 10: jp.ujihara.javax.swing.SwingUtilities.paintComponent(g, label, null, label.getBounds()); 11: } 12: ... 13: label.setBounds(xpos, ypos, w, h); 14: jp.ujihara.javax.swing.SwingUtilities.paintComponent(g, label, null, label.getBounds());
public static boolean processKeyBindings(KeyEvent event)
Process the key bindings for theComponentassociated withevent. This method is only useful ifevent.getComponent()does not descend fromJComponent, or your are not invokingsuper.processKeyEventfrom within yourJComponentsubclass.JComponentautomatically processes bindings from within itsprocessKeyEventmethod, hence you rarely need to directly invoke this method.
- Parameters:
event- KeyEvent used to identify which bindings to process, as well as which Component has focus.
- Returns:
- true if a binding has found and processed
- Since:
- 1.4
1: }finally{ 2: SwingUtilities.invokeLater(new Runnable() { 3: public void run() { 4: ... 5: KeyEvent aa =new KeyEvent(jtxt,evt.getID(),evt.getWhen(),evt.getModifiers(),evt.getKeyCode(),evt.getKeyChar(),evt.getKeyLocation()); 6: return SwingUtilities.processKeyBindings(aa); 7: } 8: ... 9: if (me.getButton()==MouseEvent.BUTTON1){ 10: Component dispatchComponent = SwingUtilities.getDeepestComponentAt( 11: this, me.getX(), me.getY());
public static void replaceUIActionMap(JComponent component, ActionMap uiActionMap)
Convenience method to change the UI ActionMap forcomponenttouiActionMap. IfuiActionMapis null, this removes any previously installed UI ActionMap.
- Since:
- 1.3
1: import javax.swing.JComponent; 2: import javax.swing.SwingUtilities; 3: import javax.swing.UIManager; 4: ... 5: } 6: SwingUtilities.replaceUIActionMap(c, map); 7: } 8: 9: static ActionMap getActionMap(Class loaderClass, String defaultsKey) {
1: import javax.swing.LookAndFeel; 2: import javax.swing.SwingUtilities; 3: import javax.swing.UIManager; 4: ... 5: window = (parentComponent instanceof Window)?(Window)parentComponent 6: :SwingUtilities.getWindowAncestor(parentComponent); 7: } 8: ... 9: if (map != null) { 10: SwingUtilities.replaceUIActionMap(tipPane, map); 11: }
1: fc.removePropertyChangeListener(model); 2: SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); 3: ... 4: SwingUtilities.replaceUIActionMap(fc, null); 5: fc.removeAncestorListener(ancestorListener); 6: ... 7: InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 8: SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); 9: ActionMap actionMap = getActionMap(); 10: ... 11: SwingUtilities.replaceUIActionMap(fc, actionMap);
1: import javax.swing.LookAndFeel; 2: import javax.swing.SwingUtilities; 3: import javax.swing.UIManager; 4: ... 5: if (inputMap != null) { 6: SwingUtilities.replaceUIInputMap( 7: group, 8: ... 9: if (map != null) { 10: SwingUtilities.replaceUIActionMap(group, map); 11: } 12: ... 13: protected void ensureVisible() { 14: SwingUtilities.invokeLater(new Runnable() {
1: import javax.swing.LookAndFeel; 2: import javax.swing.SwingUtilities; 3: import javax.swing.UIManager; 4: ... 5: if (inputMap != null) { 6: SwingUtilities.replaceUIInputMap( 7: group, 8: ... 9: if (map != null) { 10: SwingUtilities.replaceUIActionMap(group, map); 11: } 12: ... 13: protected void ensureVisible() { 14: SwingUtilities.invokeLater(new Runnable() {
public static void replaceUIInputMap(JComponent component, int type, InputMap uiInputMap)
Convenience method to change the UI InputMap forcomponenttouiInputMap. IfuiInputMapis null, this removes any previously installed UI InputMap.
- Since:
- 1.3
1: fc.removePropertyChangeListener(model); 2: SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); 3: ... 4: SwingUtilities.replaceUIActionMap(fc, null); 5: fc.removeAncestorListener(ancestorListener); 6: ... 7: InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 8: SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); 9: ActionMap actionMap = getActionMap(); 10: ... 11: SwingUtilities.replaceUIActionMap(fc, actionMap);
1: 2: SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED, inputMap); 3: LazyActionMap.installLazyActionMap(list, BasicGridListUI.class, "GridList.actionMap"); 4: ... 5: { 6: SwingUtilities.replaceUIActionMap(list, null); 7: ... 8: SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED, null); 9: } 10: ... 11: InputMap inputMap = getInputMap(JComponent.WHEN_FOCUSED); 12: SwingUtilities.replaceUIInputMap(list, JComponent.WHEN_FOCUSED,
1: import javax.swing.KeyStroke; 2: import javax.swing.SwingUtilities; 3: import javax.swing.Timer; 4: ... 5: InputMap km = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 6: SwingUtilities.replaceUIInputMap(graph, 7: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, km); 8: ... 9: km = getInputMap(JComponent.WHEN_FOCUSED); 10: SwingUtilities.replaceUIInputMap(graph, JComponent.WHEN_FOCUSED, km); 11: ... 12: SwingUtilities.replaceUIActionMap(graph, createActionMap());
1: import javax.swing.KeyStroke; 2: import javax.swing.SwingUtilities; 3: import javax.swing.Timer; 4: ... 5: if (destination != null) { 6: destination.dispatchEvent(SwingUtilities.convertMouseEvent( 7: source, mouseevent, destination)); 8: ... 9: if (destination != null) { 10: destination.dispatchEvent(SwingUtilities.convertMouseEvent( 11: source, mouseevent, destination)); 12: ... 13: InputMap inputmap = getInputMap(1); 14: SwingUtilities.replaceUIInputMap(graph, 1, inputmap);
public static void updateComponentTreeUI(Component c)
A simple minded look and feel change: ask each node in the tree toupdateUI()-- that is, to initialize its UI property with the current look and feel.
1: UIManager.setLookAndFeel(plafName); 2: SwingUtilities.updateComponentTreeUI(PlafPanel.this); 3: } 4: catch(Exception e) { e.printStackTrace(); } 5: }
1: catch (Exception e) { System.out.println(e); } 2: SwingUtilities.updateComponentTreeUI(QuickChange.this); 3: } 4: }); 5: buttonGroup.add(item);
1: import javax.swing.JPanel; 2: import javax.swing.SwingUtilities; 3: import javax.swing.WindowConstants; 4: ... 5: 6: SwingUtilities.updateComponentTreeUI(LionShareGUIMediator.getAppFrame()); 7: 8: updateThemeObservers(); 9: LionShareGUIMediator.setAppVisible(true);
1: public void actionPerformed(ActionEvent e) { 2: SwingUtilities.updateComponentTreeUI(ScribbleApp.this); 3: } 4: }));
1: protected void setTheme(final javax.swing.plaf.metal.MetalTheme t) { 2: SwingUtilities.invokeLater(new Runnable() { 3: public void run() { 4: ... 5: UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 6: SwingUtilities.updateComponentTreeUI(ApplicationFrame.this); 7: } catch (Exception e) { 8: System.out.println("Error whilst setting theme."); 9: }
public static Window windowForComponent(Component c)
Returns the firstWindowancestor ofc, or null ifcis not contained inside aWindow. Note: This method provides the same functionality asgetWindowAncestor.
- Parameters:
c-Componentto getWindowancestor of.
- Returns:
- the first
Windowancestor ofc, or null ifcis not contained inside aWindow.
1: ApolloFrame win = (ApolloFrame) 2: SwingUtilities.windowForComponent(ap); 3: 4: colouring = add(view.getColouringAction()); 5: }
1: ApolloFrame win = (ApolloFrame) 2: SwingUtilities.windowForComponent(ap); 3: colour = new JMenuItem("Plot colour ..."); 4: windowSize = new JMenuItem("Plot window length ...");
1: import javax.swing.JTextArea; 2: import javax.swing.SwingUtilities; 3: import javax.swing.border.BevelBorder; 4: ... 5: public static Window getOwner(Component aComponent) { 6: return SwingUtilities.windowForComponent(aComponent); 7: } 8: }
1: import javax.swing.JPanel; 2: import javax.swing.SwingUtilities; 3: 4: ... 5: void changeButton_actionPerformed(ActionEvent e) { 6: Color newColor = JColorChooser.showDialog(SwingUtilities.windowForComponent(this), "Choose Colour", color); 7: 8: if (newColor == null) { 9: return;