public final class WindowPositioning extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
cascade(Window window,
Class<?> cascadingClass)
Set the location of a window so that it cascades within a series of
windows.
|
static void |
fitWindowInScreen(Window window)
Move and resize a window so that it is on screen and (to the extent
possible) fits in the screen.
|
static void |
setUpBoundsMemory(Window window,
Preferences preferences)
Set the window bounds to the last saved ones, and arrange to save the
bounds for future recall by this method.
|
static void |
setUpLocationMemory(Window window,
Preferences preferences)
Set the window location to the last saved one, and arrange to save the
location for future recall by this method.
|
public static void setUpBoundsMemory(Window window, Preferences preferences)
To create a JFrame or JDialog that opens at it last known position, all you need to do is call this method once after creating (and before showing) the window. No further action is necessary (no class to extend, no method to call when the window closes).
This method is typically called by the controller object that creates the window. However, where the old-fashioned (and discouraged) practice of overriding JFrame or JDialog to add controller logic is followed, the window itself may call this method.
This method is intended for a windows that are usually singletons. For windows that will have many instances, use (TODO) instead.
The window bounds are saved per positioning class and per positioning key (null being the default key). The positioning class is any class that uniquely identifies the window type (typically the controller object's class). The optional positioning key may be used when several distinct instances of the same window need to be remembered (an example of this in MMStudio is the Preview window versus other, normal image windows).
To provide a default bounds for the window (for use when displaying for the first time in the current user profile), simply set the window bounds before calling this method.
If you want to also cascade the window, you must call this method
before calling cascade.
window - the window whose position should be restored and rememberedpreferences - Preference (node) to store Window Boundspublic static void setUpLocationMemory(Window window, Preferences preferences)
This is exactly like restoreAndMemorizeBounds, except that the
window size is not saved or restored. Recommended for use on non-
resizable windows only.
See restoreAndMemorizeBounds for further details.
window - window for which to set up location memorypreferences - Java Preferences to store location memorypublic static void cascade(Window window, Class<?> cascadingClass)
This method should be called before showing the window. If no visible
windows exist in the series specified by cascadingClass, the
window location is not altered except to fit the window in the screen.
If you want to also set up memorization for the window position, you
must call either setUpBoundsMemory or setUpLocationMemory
before calling this method.
If the window is cascaded, the remembered position is that of the oldest window in the series. However, since window positions are saved whenever windows are hidden, the program must close a group of cascaded windows in new-to-old order in order to get correct position memory behavior. Front-to-back order might be a good enough approximation to this.
window - the window to positioncascadingClass - a class that identifies the group of windows to be
cascaded with respect to each otherpublic static void fitWindowInScreen(Window window)
This keeps the window in the same screen as much as possible. To position a window in a particular screen, move it into that screen before calling this method.
There is no need to call this method if position memory is set up or cascading is enabled for the window (those methods internally call this method).
window - the window to fit in the screenCopyright © 2023. All rights reserved.