模块 java.desktop

类 PopupFactory

java.lang.Object
javax.swing.PopupFactory

public class PopupFactory extends Object
PopupFactory 顾名思义,用于获取 Popup 的实例。 Popup s 用于在特定包含层次结构中显示 Component 高于所有其他 Component s。一般合同是,一旦您从 PopupFactory 获得了 Popup,您必须在 Popup 上调用 hide。典型用法是:
  PopupFactory factory = PopupFactory.getSharedInstance();
  Popup popup = factory.getPopup(owner, contents, x, y);
  popup.show();
  ...
  popup.hide();
 
自从:
1.4
参见:
  • 构造方法详细信息

    • PopupFactory

      public PopupFactory()
      构造一个 PopupFactory
  • 方法详情

    • setSharedInstance

      public static void setSharedInstance(PopupFactory  factory)
      设置将用于获取 PopupPopupFactory。如果 factory 为空,这将抛出一个 IllegalArgumentException
      参数:
      factory - 共享 PopupFactory
      抛出:
      IllegalArgumentException - 如果 factory 为空
      参见:
    • getSharedInstance

      public static PopupFactory  getSharedInstance()
      返回可用于获取 Popup 的共享 PopupFactory
      返回:
      共享弹出工厂
    • getPopup

      public Popup  getPopup(Component  owner, Component  contents, int x, int y) throws IllegalArgumentException
      为包含组件 contents 的组件 owner 创建一个 Popupowner 用于确定哪个 Window 新的 Popup 将成为 Component Popup 创建的父级。 null owner 表示没有有效的父级。 xy 指定放置 Popup 的首选初始位置。根据屏幕尺寸或其他参数,Popup 可能不会显示在 xy 上。
      参数:
      owner - 组件鼠标坐标相对于,可能为空
      contents - 弹出窗口的内容
      x - 初始 x 屏幕坐标
      y - 初始 y 屏幕坐标
      返回:
      包含内容的弹出窗口
      抛出:
      IllegalArgumentException - 如果内容为空
    • getPopup

      protected Popup  getPopup(Component  owner, Component  contents, int x, int y, boolean isHeavyWeightPopup) throws IllegalArgumentException
      为包含组件 contents 的组件 owner 创建一个 Popup。包含组件 owner 的窗口将用作父窗口。 null owner 表示没有有效的父级。 xy 指定放置 Popup 的首选初始位置。根据屏幕尺寸或其他参数,Popup 可能不会显示在 xy 上。 isHeavyWeightPopup 指定 Popup 是否为重量级。传递true将强制Popup类型为重量级,否则Popup类型将由Popup工厂选择。轻量级 Popup 窗口比重量级(本机对等)窗口更有效,但轻量级和重量级组件在 GUI 中不能很好地混合。此方法仅供 PopupFactory 子类使用。
      参数:
      owner - 组件鼠标坐标相对于,可能为空
      contents - 弹出窗口的内容
      x - 初始 x 屏幕坐标
      y - 初始 y 屏幕坐标
      isHeavyWeightPopup - 如果 Popup 应该是重量级的,则为真,否则弹出类型将由弹出工厂选择。
      返回:
      包含内容的弹出窗口
      抛出:
      IllegalArgumentException - 如果内容为空