Package org.jdesktop.swingx.util
Class WindowUtils
- java.lang.Object
-
- org.jdesktop.swingx.util.WindowUtils
-
public final class WindowUtils extends java.lang.ObjectEncapsulates various utilities for windows (ie:FrameandDialogobjects and descendants, in particular).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWindowUtils.MinSizeComponentListenerResets window size to minSize if needed.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.swing.JDialogfindJDialog(java.awt.Component c)Locates the JDialog for the given componentstatic javax.swing.JFramefindJFrame(java.awt.Component c)Locates the JFrame for the given componentstatic javax.swing.RootPaneContainerfindRootPaneContainer(java.awt.Component c)Locates the RootPaneContainer for the given componentstatic java.awt.WindowfindWindow(java.awt.Component c)static java.util.List<java.awt.Component>getAllComponents(java.awt.Container c)static java.awt.PointgetPointForCentering(java.awt.Window window)Returns thePointat which a window should be placed to center that window on the screen.static java.awt.PointgetPointForCentering(javax.swing.JInternalFrame window)Returns thePointat which a window should be placed to center that window on the given desktop.static java.awt.PointgetPointForStaggering(java.awt.Window originWindow)Returns thePointat which a window should be placed in order to be staggered slightly from another "origin" window to ensure that the title areas of both windows remain visible to the user.static java.awt.RectanglegetRectangle(java.awt.Window win)Get aRectangleobject representing the given window's position and magnitude in space.static java.awt.RectanglegetRectangle(javax.swing.JComponent comp)Get aRectangleobject representing the given JComponent's position and magnitude in space.static voidsetConstraints(java.awt.GridBagConstraints gbc, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, int top, int left, int bottom, int right)Utility method used to load a GridBagConstraints object (param gbc) with the data in the other parameters.static voidsetFontRecursively(java.awt.Container c, java.awt.Font font)static voidsetMinimumSizeManager(java.awt.Window window, int minWidth, int minHeight)Installs/resets a ComponentListener to resize the given window to minWidth/Height if needed.
-
-
-
Method Detail
-
getPointForCentering
public static java.awt.Point getPointForCentering(java.awt.Window window)
Returns thePointat which a window should be placed to center that window on the screen. Some thought was taken as to whether to implement a method such as this, or to simply make a method that, given a window, will center it. It was decided that it is better to not alter an object within a method.- Parameters:
window- The window to calculate the center point for. This object can not be null.- Returns:
- the
Pointat which the window should be placed to center that window on the screen.
-
getPointForCentering
public static java.awt.Point getPointForCentering(javax.swing.JInternalFrame window)
Returns thePointat which a window should be placed to center that window on the given desktop. Some thought was taken as to whether to implement a method such as this, or to simply make a method that, given a window, will center it. It was decided that it is better to not alter an object within a method.- Parameters:
window- The window (JInternalFrame) to calculate the center point for. This object can not be null.- Returns:
- the
Pointat which the window should be placed to center that window on the given desktop
-
getPointForStaggering
public static java.awt.Point getPointForStaggering(java.awt.Window originWindow)
Returns thePointat which a window should be placed in order to be staggered slightly from another "origin" window to ensure that the title areas of both windows remain visible to the user.- Parameters:
originWindow- Window from which the staggered location will be calculated- Returns:
- location staggered from the upper left location of the origin window
-
setConstraints
public static void setConstraints(java.awt.GridBagConstraints gbc, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, int top, int left, int bottom, int right)Utility method used to load a GridBagConstraints object (param gbc) with the data in the other parameters. This method saves code space over doing the assignments by hand, and also allows you to reuse the same GridBagConstraints object reducing temporary object creating (at the expense of a method call. Go figure).
-
getRectangle
public static java.awt.Rectangle getRectangle(java.awt.Window win)
Get aRectangleobject representing the given window's position and magnitude in space.- Parameters:
win- The window to get a Rectangle object for- Returns:
- a Rectangle object. @see com.jgui.Rectangle
-
getRectangle
public static java.awt.Rectangle getRectangle(javax.swing.JComponent comp)
Get aRectangleobject representing the given JComponent's position and magnitude in space.- Parameters:
comp- The JComponent to get a Rectangle object for- Returns:
- a Rectangle object. @see com.jgui.Rectangle
-
findRootPaneContainer
public static javax.swing.RootPaneContainer findRootPaneContainer(java.awt.Component c)
Locates the RootPaneContainer for the given component- Parameters:
c-- Returns:
- the RootPaneContainer to which the component belongs to
-
findJFrame
public static javax.swing.JFrame findJFrame(java.awt.Component c)
Locates the JFrame for the given component- Parameters:
c-- Returns:
- the JFrame to which the component belongs to
-
findJDialog
public static javax.swing.JDialog findJDialog(java.awt.Component c)
Locates the JDialog for the given component- Parameters:
c-- Returns:
- the JDialog to which the component belongs to
-
findWindow
public static java.awt.Window findWindow(java.awt.Component c)
-
getAllComponents
public static java.util.List<java.awt.Component> getAllComponents(java.awt.Container c)
-
setFontRecursively
public static void setFontRecursively(java.awt.Container c, java.awt.Font font)
-
setMinimumSizeManager
public static void setMinimumSizeManager(java.awt.Window window, int minWidth, int minHeight)Installs/resets a ComponentListener to resize the given window to minWidth/Height if needed.- Parameters:
window-minWidth-minHeight-
-
-