javax.swing.Popup的应用

类别:Java 点击:0 评论:0 推荐:

我们先来看看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();
这样就可以只有一个标签的窗口放在屏幕的任何位置了。
往往可以用,在鼠标移动时,来显示一些临时的信息等等。

本文地址:http://com.8s8s.com/it/it13825.htm