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();
這樣就可以只有一個標籤的窗口放在屏幕的任何位置了。
往往可以用,在鼠標移動時,來顯示一些臨時的信息等等。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章