javax.swing.Popup的應用

來源:互聯網
上載者:User

我們先來看看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();
這樣就可以只有一個標籤的視窗放在螢幕的任何位置了。
往往可以用,在滑鼠移動時,來顯示一些臨時的資訊等等。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.