net.sf.swinglib
Class SwingUtil

java.lang.Object
  extended by net.sf.swinglib.SwingUtil

public class SwingUtil
extends Object

A collection of static methods that don't really fit anywhere else.


Constructor Summary
SwingUtil()
           
 
Method Summary
static void center(Window window)
          Updates the passed window's position to center it with respect to the screen.
static void center(Window window, Window inWindow)
          Updates the first window's position to center it with respect to the second window.
static void centerAndShow(Window window)
          Centers the passed window (dialog or frame) on the screen and makes it visible.
static void centerAndShow(Window window, Window inWindow)
          Centers the passed window (dialog or frame) within the second window and makes it visible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingUtil

public SwingUtil()
Method Detail

centerAndShow

public static void centerAndShow(Window window)
Centers the passed window (dialog or frame) on the screen and makes it visible. This is typically used to display the main window for an application.


centerAndShow

public static void centerAndShow(Window window,
                                 Window inWindow)
Centers the passed window (dialog or frame) within the second window and makes it visible. This is typically used to display a dialog.

The second window may be null, in which case the first is centered within the screen. This is a convenience for ownerless dialogs.


center

public static void center(Window window)
Updates the passed window's position to center it with respect to the screen. May be called before or after the window is made visible (but remember to call pack() first!).

Deals with multi-monitor setups via the following hack: if the screen size reported by the default toolkit has a width:height ration > 2:1, then the width is divided by 2. This works well for 1, 2, or 3 screen desktops: the window will appear in the left screen of a 2-screen setup, in the middle of a 3-screen setup.

If the window is larger than the screen size, it's positioned at the top-left corner. Hopefully the user will be able to shrink it.


center

public static void center(Window window,
                          Window inWindow)
Updates the first window's position to center it with respect to the second window. If the first window is larger than the second, it will be offset to the top/left as needed, but not exceeding the bounds of the screen.

The second window may be null, in which case the first is centered within the screen. This is a convenience for ownerless dialogs.