java.lang.Object
javax.swing.PopupFactory
PopupFactory,顾名思义,用于获取Popup的实例。 Popup用于在特定包含层次结构中的所有其他Component上方显示Component。一般约定是,一旦您从PopupFactory获取了Popup,必须在Popup上调用hide。典型用法是:
PopupFactory factory = PopupFactory.getSharedInstance(); Popup popup = factory.getPopup(owner, contents, x, y); popup.show(); ... popup.hide();
- 自 JDK 版本:
- 1.4
- 参见:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription为包含contents的owner组件创建一个Popup。protected Popup为包含contents的owner组件创建一个Popup。static PopupFactory返回共享的PopupFactory,可用于获取Popup。static voidsetSharedInstance(PopupFactory factory) 设置将用于获取Popup的PopupFactory。
-
Constructor Details
-
PopupFactory
public PopupFactory()构造一个PopupFactory。
-
-
Method Details
-
getPopup
public Popup getPopup(Component owner, Component contents, int x, int y) throws IllegalArgumentException 为包含contents的owner组件创建一个Popup。使用owner来确定新Popup将父级Component创建到的Window。null的owner意味着没有有效的父级。x和y指定放置Popup的首选初始位置。根据屏幕大小或其他参数,Popup可能不会显示在x和y处。- 参数:
-
owner- 鼠标坐标相对于的组件,可能为null -
contents- Popup的内容 -
x- 初始x屏幕坐标 -
y- 初始y屏幕坐标 - 返回:
- 包含内容的Popup
- 抛出:
-
IllegalArgumentException- 如果内容为null
-
getPopup
protected Popup getPopup(Component owner, Component contents, int x, int y, boolean isHeavyWeightPopup) throws IllegalArgumentException 为包含contents的owner组件创建一个Popup。包含组件owner的窗口将用作父窗口。null的owner意味着没有有效的父级。x和y指定放置Popup的首选初始位置。根据屏幕大小或其他参数,Popup可能不会显示在x和y处。isHeavyWeightPopup指定Popup是否为重量级。传递true将强制Popup类型为重量级,否则Popup类型将由Popup工厂选择。轻量级Popup窗口比重量级(本机对等体)窗口更有效,但轻量级和重量级组件在GUI中不搭配。此方法仅供PopupFactory子类使用。- 参数:
-
owner- 鼠标坐标相对于的组件,可能为null -
contents- Popup的内容 -
x- 初始x屏幕坐标 -
y- 初始y屏幕坐标 -
isHeavyWeightPopup- 如果Popup应为重量级,则为true,否则Popup类型将由Popup工厂选择。 - 返回:
- 包含内容的Popup
- 抛出:
-
IllegalArgumentException- 如果内容为null