javax.swing.Popup的应用

我们先来看看javax.swing.Popup的javadoc中的描述:
Popups are used to display a Component to the user, typically on top of all the other Components in a particular containment hierarchy. Popups have a very small life cycle. Once you have obtained a Popup, and hidden it (invoked the hide method), you should no longer invoke any methods on it. This allows the PopupFactory to cache Popups for later use.

The general contract is that if you need to change the size of the Component, or location of the Popup, you should obtain a new Popup.

Popup does not descend from Component, rather implementations of Popup are responsible for creating and maintaining their own Components to render the requested Component to the user.

You typically do not explicitly create an instance of Popup, instead obtain one from a PopupFactory.

大致意思就是popup可以把一个组件显示在窗口的顶层,一般说来它只有很短的生命周期……还有就是建议利用PopupFactory来获取实例。<p>
Popup的一个典型用法就是toolTip你可以从tooltip的源码中看到。

这里给出简单的例子:
Popup mypopup = PopupFactory.getSharedInstance().getPopup(frame,
          new JLabel("popupwindow"), posx,posy);
 mypopup.show();
这样就可以只有一个标签的窗口放在屏幕的任何位置了。
往往可以用,在鼠标移动时,来显示一些临时的信息等等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值