APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class PopupFactory

extends Object
Class Inheritance
Imports
java.awt.BorderLayout, .Component, .Container, .GraphicsConfiguration, .GraphicsEnvironment, .Insets, .Panel, .Point, .Rectangle, .Toolkit, .Window, java.awt.event.WindowAdapter, .WindowEvent, java.util.ArrayList, .HashMap, .List, .Map, sun.awt.EmbeddedFrame, .OSInfo, sun.swing.SwingAccessor

PopupFactory, as the name implies, is used to obtain instances of Popups. Popups are used to display a Component above all other Components in a particular containment hierarchy. The general contract is that once you have obtained a Popup from a PopupFactory, you must invoke hide on the Popup. The typical usage is:
  PopupFactory factory = PopupFactory.getSharedInstance();
  Popup popup = factory.getPopup(owner, contents, x, y);
  popup.show();
  ...
  popup.hide();
Since
1.4
See Also
Popup

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PopupFactory.ContainerPopup

ContainerPopup consolidates the common code used in the light/medium weight implementations of Popup.

private static class
PopupFactory.HeadlessPopup

Popup implementation that is used in headless environment.

private static class
PopupFactory.HeavyWeightPopup

Popup implementation that uses a Window as the popup.

private static class
PopupFactory.LightWeightPopup

Popup implementation that uses a JPanel as the popup.

private static class
PopupFactory.MediumWeightPopup

Popup implementation that uses a Panel as the popup.

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
LIGHT_WEIGHT_POPUP

Key used to indicate a light weight popup should be used.

private static final int
MAX_CACHE_SIZE

Max number of items to store in any one particular cache.

pack-priv static final int
MEDIUM_WEIGHT_POPUP

Key used to indicate a medium weight Popup should be used.

private int
popupType

Default type of Popup to create.

pack-priv static PopupFactory

Constructor Summary

AccessConstructor and Description
public
PopupFactory()

Constructs a PopupFactory.

Method Summary

Modifier and TypeMethod and Description
private Popup
getHeadlessPopup(Component owner, Component contents, int ownerX, int ownerY)

Creates a headless popup

private Popup
getHeavyWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Creates a heavy weight popup.

private Popup
getLightWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Creates a light weight popup.

private Popup
getMediumWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Creates a medium weight popup.

public Popup

Returns:

Popup containing Contents
getPopup
(Component
Component mouse coordinates are relative to, may be null
owner
,
Component
Contents of the Popup
contents
,
int
Initial x screen coordinate
x
,
int
Initial y screen coordinate
y
)

Creates a Popup for the Component owner containing the Component contents.

protected Popup

Returns:

Popup containing Contents
getPopup
(Component
Component mouse coordinates are relative to, may be null
owner
,
Component
Contents of the Popup
contents
,
int
Initial x screen coordinate
x
,
int
Initial y screen coordinate
y
,
boolean
true if Popup should be heavy weight, otherwise popup type will be selected by popup factory.
isHeavyWeightPopup
)

Creates a Popup for the Component owner containing the Component contents.

private Popup
getPopup(Component owner, Component contents, int ownerX, int ownerY, int popupType)

Obtains the appropriate Popup based on popupType.

pack-priv int
getPopupType()

Returns the preferred type of Popup to create.

private int
getPopupType(Component owner, Component contents, int ownerX, int ownerY)

Returns the popup type to use for the specified parameters.

public static PopupFactory

Returns:

Shared PopupFactory
getSharedInstance
()

Returns the shared PopupFactory which can be used to obtain Popups.

private boolean
invokerInHeavyWeightPopup(Component i)

Returns true if the Component i inside a heavy weight Popup.

pack-priv void
setPopupType(int type)

Provides a hint as to the type of Popup that should be created.

public static void
setSharedInstance(PopupFactory
Shared PopupFactory
factory
)

Sets the PopupFactory that will be used to obtain Popups.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HEAVY_WEIGHT_POPUPback to summary
pack-priv static final int HEAVY_WEIGHT_POPUP
LIGHT_WEIGHT_POPUPback to summary
pack-priv static final int LIGHT_WEIGHT_POPUP

Key used to indicate a light weight popup should be used.

MAX_CACHE_SIZEback to summary
private static final int MAX_CACHE_SIZE

Max number of items to store in any one particular cache.

MEDIUM_WEIGHT_POPUPback to summary
pack-priv static final int MEDIUM_WEIGHT_POPUP

Key used to indicate a medium weight Popup should be used.

popupTypeback to summary
private int popupType

Default type of Popup to create.

sharedFactoryback to summary
pack-priv static PopupFactory sharedFactory

Constructor Detail

PopupFactoryback to summary
public PopupFactory()

Constructs a PopupFactory.

Method Detail

getHeadlessPopupback to summary
private Popup getHeadlessPopup(Component owner, Component contents, int ownerX, int ownerY)

Creates a headless popup

getHeavyWeightPopupback to summary
private Popup getHeavyWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Creates a heavy weight popup.

getLightWeightPopupback to summary
private Popup getLightWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Creates a light weight popup.

getMediumWeightPopupback to summary
private Popup getMediumWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Creates a medium weight popup.

getPopupback to summary
public Popup getPopup(Component owner, Component contents, int x, int y) throws IllegalArgumentException

Creates a Popup for the Component owner containing the Component contents. owner is used to determine which Window the new Popup will parent the Component the Popup creates to. A null owner implies there is no valid parent. x and y specify the preferred initial location to place the Popup at. Based on screen size, or other parameters, the Popup may not display at x and y.

Parameters
owner:Component

Component mouse coordinates are relative to, may be null

contents:Component

Contents of the Popup

x:int

Initial x screen coordinate

y:int

Initial y screen coordinate

Returns:Popup

Popup containing Contents

Exceptions
IllegalArgumentException:
if contents is null
getPopupback to summary
protected Popup getPopup(Component owner, Component contents, int x, int y, boolean isHeavyWeightPopup) throws IllegalArgumentException

Creates a Popup for the Component owner containing the Component contents. The window containing the component owner will be used as the parent window. A null owner implies there is no valid parent. x and y specify the preferred initial location to place the Popup at. Based on screen size, or other parameters, the Popup may not display at x and y. isHeavyWeightPopup specifies if the Popup will be heavyweight. Passing true will force the Popup type to be heavyweight, otherwise Popup type will be selected by Popup factory. Lightweight Popup windows are more efficient than heavyweight (native peer) windows, but lightweight and heavyweight components do not mix well in a GUI. This method is intended to be used only by PopupFactory sub-classes.

Parameters
owner:Component

Component mouse coordinates are relative to, may be null

contents:Component

Contents of the Popup

x:int

Initial x screen coordinate

y:int

Initial y screen coordinate

isHeavyWeightPopup:boolean

true if Popup should be heavy weight, otherwise popup type will be selected by popup factory.

Returns:Popup

Popup containing Contents

Exceptions
IllegalArgumentException:
if contents is null
getPopupback to summary
private Popup getPopup(Component owner, Component contents, int ownerX, int ownerY, int popupType)

Obtains the appropriate Popup based on popupType.

getPopupTypeback to summary
pack-priv int getPopupType()

Returns the preferred type of Popup to create.

getPopupTypeback to summary
private int getPopupType(Component owner, Component contents, int ownerX, int ownerY)

Returns the popup type to use for the specified parameters.

getSharedInstanceback to summary
public static PopupFactory getSharedInstance()

Returns the shared PopupFactory which can be used to obtain Popups.

Returns:PopupFactory

Shared PopupFactory

invokerInHeavyWeightPopupback to summary
private boolean invokerInHeavyWeightPopup(Component i)

Returns true if the Component i inside a heavy weight Popup.

setPopupTypeback to summary
pack-priv void setPopupType(int type)

Provides a hint as to the type of Popup that should be created.

setSharedInstanceback to summary
public static void setSharedInstance(PopupFactory factory)

Sets the PopupFactory that will be used to obtain Popups. This will throw an IllegalArgumentException if factory is null.

Parameters
factory:PopupFactory

Shared PopupFactory

Exceptions
IllegalArgumentException:
if factory is null
See Also
getPopup
javax.swing back to summary

private Class PopupFactory.ContainerPopup

extends Popup
Class Inheritance
Known Direct Subclasses
javax.swing.PopupFactory.HeadlessPopup, javax.swing.PopupFactory.LightWeightPopup, javax.swing.PopupFactory.MediumWeightPopup

ContainerPopup consolidates the common code used in the light/medium weight implementations of Popup.

Field Summary

Modifier and TypeField and Description
pack-priv Component
owner

Component we are to be added to.

pack-priv int
x

Desired x location.

pack-priv int
y

Desired y location.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
fitsOnScreen()

Returns true if popup can fit the screen and the owner's top parent.

pack-priv Rectangle
public void
hide()

Overrides javax.swing.Popup.hide.

Hides and disposes of the Popup.

pack-priv boolean
public void
pack()

Overrides javax.swing.Popup.pack.

Causes the Popup to be sized to fit the preferred size of the Component it contains.

pack-priv void
reset(Component owner, Component contents, int ownerX, int ownerY)

Overrides javax.swing.Popup.reset.

Resets the Popup to an initial state.

Inherited from javax.swing.Popup:
createComponentdisposegetComponentshow

Field Detail

ownerback to summary
pack-priv Component owner

Component we are to be added to.

xback to summary
pack-priv int x

Desired x location.

yback to summary
pack-priv int y

Desired y location.

Constructor Detail

ContainerPopupback to summary
private ContainerPopup()

Method Detail

fitsOnScreenback to summary
pack-priv boolean fitsOnScreen()

Returns true if popup can fit the screen and the owner's top parent. It determines can popup be lightweight or mediumweight.

getContainerPopupAreaback to summary
pack-priv Rectangle getContainerPopupArea(GraphicsConfiguration gc)
hideback to summary
public void hide()

Overrides javax.swing.Popup.hide.

Doc from javax.swing.Popup.hide.

Hides and disposes of the Popup. Once a Popup has been disposed you should no longer invoke methods on it. A disposed Popup may be reclaimed and later used based on the PopupFactory. As such, if you invoke methods on a disposed Popup, indeterminate behavior will result.

overlappedByOwnedWindowback to summary
pack-priv boolean overlappedByOwnedWindow()
packback to summary
public void pack()

Overrides javax.swing.Popup.pack.

Doc from javax.swing.Popup.pack.

Causes the Popup to be sized to fit the preferred size of the Component it contains.

resetback to summary
pack-priv void reset(Component owner, Component contents, int ownerX, int ownerY)

Overrides javax.swing.Popup.reset.

Doc from javax.swing.Popup.reset.

Resets the Popup to an initial state.

javax.swing back to summary

private Class PopupFactory.HeadlessPopup

extends ContainerPopup
Class Inheritance

Popup implementation that is used in headless environment.

Field Summary

Inherited from javax.swing.PopupFactory.ContainerPopup:
ownerxy

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv Component
createComponent(Component owner)

Overrides javax.swing.Popup.createComponent.

Creates the Component to use as the parent of the Popup.

pack-priv static Popup
getHeadlessPopup(Component owner, Component contents, int ownerX, int ownerY)

public void
hide()

Overrides javax.swing.PopupFactory.ContainerPopup.hide.

Hides and disposes of the Popup.

public void
show()

Overrides javax.swing.Popup.show.

Makes the Popup visible.

Inherited from javax.swing.PopupFactory.ContainerPopup:
fitsOnScreengetContainerPopupAreaoverlappedByOwnedWindowpackreset

Constructor Detail

HeadlessPopupback to summary
private HeadlessPopup()

Method Detail

createComponentback to summary
pack-priv Component createComponent(Component owner)

Overrides javax.swing.Popup.createComponent.

Doc from javax.swing.Popup.createComponent.

Creates the Component to use as the parent of the Popup. The default implementation creates a Window, subclasses should override.

getHeadlessPopupback to summary
pack-priv static Popup getHeadlessPopup(Component owner, Component contents, int ownerX, int ownerY)
hideback to summary
public void hide()

Overrides javax.swing.PopupFactory.ContainerPopup.hide.

Doc from javax.swing.Popup.hide.

Hides and disposes of the Popup. Once a Popup has been disposed you should no longer invoke methods on it. A disposed Popup may be reclaimed and later used based on the PopupFactory. As such, if you invoke methods on a disposed Popup, indeterminate behavior will result.

showback to summary
public void show()

Overrides javax.swing.Popup.show.

Doc from javax.swing.Popup.show.

Makes the Popup visible. If the Popup is currently visible, this has no effect.

javax.swing back to summary

private Class PopupFactory.HeavyWeightPopup

extends Popup
Class Inheritance

Popup implementation that uses a Window as the popup.

Field Summary

Modifier and TypeField and Description
private static Map<Window, List<PopupFactory.HeavyWeightPopup>>
private volatile boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
dispose()

Overrides javax.swing.Popup.dispose.

As we recycle the Window, we don't want to dispose of it, thus this method does nothing, instead use _dispose which will handle the disposing.

pack-priv static Popup
getHeavyWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Returns either a new or recycled Popup containing the specified children.

private static Map<Window, List<PopupFactory.HeavyWeightPopup>>
getHeavyWeightPopupCache()

Returns the cache to use for heavy weight popups.

private static PopupFactory.HeavyWeightPopup
getRecycledHeavyWeightPopup(Window w)

Returns a previously disposed heavy weight Popup associated with window.

public void
hide()

Overrides javax.swing.Popup.hide.

Hides and disposes of the Popup.

private static void
recycleHeavyWeightPopup(PopupFactory.HeavyWeightPopup popup)

Recycles the passed in HeavyWeightPopup.

pack-priv void
setCacheEnabled(boolean enable)

Enables or disables cache for current object.

Inherited from javax.swing.Popup:
createComponentgetComponentpackresetshow

Field Detail

cacheback to summary
private static Map<Window, List<PopupFactory.HeavyWeightPopup>> cache
isCacheEnabledback to summary
private volatile boolean isCacheEnabled

Constructor Detail

HeavyWeightPopupback to summary
private HeavyWeightPopup()

Method Detail

_disposeback to summary
pack-priv void _dispose()
disposeback to summary
pack-priv void dispose()

Overrides javax.swing.Popup.dispose.

As we recycle the Window, we don't want to dispose of it, thus this method does nothing, instead use _dispose which will handle the disposing.

getHeavyWeightPopupback to summary
pack-priv static Popup getHeavyWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Returns either a new or recycled Popup containing the specified children.

getHeavyWeightPopupCacheback to summary
private static Map<Window, List<PopupFactory.HeavyWeightPopup>> getHeavyWeightPopupCache()

Returns the cache to use for heavy weight popups. Maps from Window to a List of HeavyWeightPopups.

getRecycledHeavyWeightPopupback to summary
private static PopupFactory.HeavyWeightPopup getRecycledHeavyWeightPopup(Window w)

Returns a previously disposed heavy weight Popup associated with window. This will return null if there is no HeavyWeightPopup associated with window.

hideback to summary
public void hide()

Overrides javax.swing.Popup.hide.

Doc from javax.swing.Popup.hide.

Hides and disposes of the Popup. Once a Popup has been disposed you should no longer invoke methods on it. A disposed Popup may be reclaimed and later used based on the PopupFactory. As such, if you invoke methods on a disposed Popup, indeterminate behavior will result.

recycleHeavyWeightPopupback to summary
private static void recycleHeavyWeightPopup(PopupFactory.HeavyWeightPopup popup)

Recycles the passed in HeavyWeightPopup.

setCacheEnabledback to summary
pack-priv void setCacheEnabled(boolean enable)

Enables or disables cache for current object.

javax.swing back to summary

private Class PopupFactory.LightWeightPopup

extends ContainerPopup
Class Inheritance

Popup implementation that uses a JPanel as the popup.

Field Summary

Modifier and TypeField and Description
private static List<PopupFactory.LightWeightPopup>
private static final Object
Inherited from javax.swing.PopupFactory.ContainerPopup:
ownerxy

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv Component
createComponent(Component owner)

Overrides javax.swing.Popup.createComponent.

Creates the Component to use as the parent of the Popup.

pack-priv static Popup
getLightWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Returns a light weight Popup implementation.

private static List<PopupFactory.LightWeightPopup>
getLightWeightPopupCache()

Returns the cache to use for heavy weight popups.

private static PopupFactory.LightWeightPopup
getRecycledLightWeightPopup()

Returns a previously used LightWeightPopup, or null if none of the popups have been recycled.

public void
hide()

Overrides javax.swing.PopupFactory.ContainerPopup.hide.

Hides and disposes of the Popup.

private static void
recycleLightWeightPopup(PopupFactory.LightWeightPopup popup)

Recycles the LightWeightPopup popup.

pack-priv void
reset(Component owner, Component contents, int ownerX, int ownerY)

Overrides javax.swing.PopupFactory.ContainerPopup.reset.

Resets the Popup to an initial state.

public void
show()

Overrides javax.swing.Popup.show.

Makes the Popup visible.

Inherited from javax.swing.PopupFactory.ContainerPopup:
fitsOnScreengetContainerPopupAreaoverlappedByOwnedWindowpack

Field Detail

cacheback to summary
private static List<PopupFactory.LightWeightPopup> cache
lightWeightPopupCacheKeyback to summary
private static final Object lightWeightPopupCacheKey

Constructor Detail

LightWeightPopupback to summary
private LightWeightPopup()

Method Detail

createComponentback to summary
pack-priv Component createComponent(Component owner)

Overrides javax.swing.Popup.createComponent.

Doc from javax.swing.Popup.createComponent.

Creates the Component to use as the parent of the Popup. The default implementation creates a Window, subclasses should override.

getLightWeightPopupback to summary
pack-priv static Popup getLightWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Returns a light weight Popup implementation. If the Popup needs more space that in available in owner, this will return null.

getLightWeightPopupCacheback to summary
private static List<PopupFactory.LightWeightPopup> getLightWeightPopupCache()

Returns the cache to use for heavy weight popups.

getRecycledLightWeightPopupback to summary
private static PopupFactory.LightWeightPopup getRecycledLightWeightPopup()

Returns a previously used LightWeightPopup, or null if none of the popups have been recycled.

hideback to summary
public void hide()

Overrides javax.swing.PopupFactory.ContainerPopup.hide.

Doc from javax.swing.Popup.hide.

Hides and disposes of the Popup. Once a Popup has been disposed you should no longer invoke methods on it. A disposed Popup may be reclaimed and later used based on the PopupFactory. As such, if you invoke methods on a disposed Popup, indeterminate behavior will result.

recycleLightWeightPopupback to summary
private static void recycleLightWeightPopup(PopupFactory.LightWeightPopup popup)

Recycles the LightWeightPopup popup.

resetback to summary
pack-priv void reset(Component owner, Component contents, int ownerX, int ownerY)

Overrides javax.swing.PopupFactory.ContainerPopup.reset.

Resets the Popup to an initial state.

showback to summary
public void show()

Overrides javax.swing.Popup.show.

Doc from javax.swing.Popup.show.

Makes the Popup visible. If the Popup is currently visible, this has no effect.

javax.swing back to summary

private Class PopupFactory.MediumWeightPopup

extends ContainerPopup
Class Inheritance

Popup implementation that uses a Panel as the popup.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static List<PopupFactory.MediumWeightPopup>
private JRootPane
rootPane

Child of the panel.

Inherited from javax.swing.PopupFactory.ContainerPopup:
ownerxy

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv Component
createComponent(Component owner)

Overrides javax.swing.Popup.createComponent.

Creates the Component to use as the parent of the Popup.

pack-priv static Popup
getMediumWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Returns a medium weight Popup implementation.

private static List<PopupFactory.MediumWeightPopup>
getMediumWeightPopupCache()

Returns the cache to use for medium weight popups.

private static PopupFactory.MediumWeightPopup
getRecycledMediumWeightPopup()

Returns a previously used MediumWeightPopup, or null if none of the popups have been recycled.

public void
hide()

Overrides javax.swing.PopupFactory.ContainerPopup.hide.

Hides and disposes of the Popup.

private static void
recycleMediumWeightPopup(PopupFactory.MediumWeightPopup popup)

Recycles the MediumWeightPopup popup.

pack-priv void
reset(Component owner, Component contents, int ownerX, int ownerY)

Overrides javax.swing.PopupFactory.ContainerPopup.reset.

Resets the Popup to an initial state.

public void
show()

Overrides javax.swing.Popup.show.

Makes the Popup visible.

Inherited from javax.swing.PopupFactory.ContainerPopup:
fitsOnScreengetContainerPopupAreaoverlappedByOwnedWindowpack

Field Detail

cacheback to summary
private static List<PopupFactory.MediumWeightPopup> cache
rootPaneback to summary
private JRootPane rootPane

Child of the panel. The contents are added to this.

Constructor Detail

MediumWeightPopupback to summary
private MediumWeightPopup()

Method Detail

createComponentback to summary
pack-priv Component createComponent(Component owner)

Overrides javax.swing.Popup.createComponent.

Doc from javax.swing.Popup.createComponent.

Creates the Component to use as the parent of the Popup. The default implementation creates a Window, subclasses should override.

getMediumWeightPopupback to summary
pack-priv static Popup getMediumWeightPopup(Component owner, Component contents, int ownerX, int ownerY)

Returns a medium weight Popup implementation. If the Popup needs more space that in available in owner, this will return null.

getMediumWeightPopupCacheback to summary
private static List<PopupFactory.MediumWeightPopup> getMediumWeightPopupCache()

Returns the cache to use for medium weight popups.

getRecycledMediumWeightPopupback to summary
private static PopupFactory.MediumWeightPopup getRecycledMediumWeightPopup()

Returns a previously used MediumWeightPopup, or null if none of the popups have been recycled.

hideback to summary
public void hide()

Overrides javax.swing.PopupFactory.ContainerPopup.hide.

Doc from javax.swing.Popup.hide.

Hides and disposes of the Popup. Once a Popup has been disposed you should no longer invoke methods on it. A disposed Popup may be reclaimed and later used based on the PopupFactory. As such, if you invoke methods on a disposed Popup, indeterminate behavior will result.

recycleMediumWeightPopupback to summary
private static void recycleMediumWeightPopup(PopupFactory.MediumWeightPopup popup)

Recycles the MediumWeightPopup popup.

resetback to summary
pack-priv void reset(Component owner, Component contents, int ownerX, int ownerY)

Overrides javax.swing.PopupFactory.ContainerPopup.reset.

Resets the Popup to an initial state.

showback to summary
public void show()

Overrides javax.swing.Popup.show.

Doc from javax.swing.Popup.show.

Makes the Popup visible. If the Popup is currently visible, this has no effect.

javax.swing back to summary

private Class PopupFactory.MediumWeightPopup.MediumWeightComponent

extends Panel
implements SwingHeavyWeight
Class Inheritance
All Implemented Interfaces
javax.swing.SwingHeavyWeight
Annotations
@SuppressWarnings:serial

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.awt.Panel:
addNotifygetAccessibleContext

Constructor Detail

MediumWeightComponentback to summary
pack-priv MediumWeightComponent()