component must be showing on the screen to determine its location

來源:互聯網
上載者:User

使用JPopupMenu控制項時,遭遇component must be showing on the screen to determine its location

    在一個Swing開發的應用介面中,使用JPopupMenu控制項,結果發現,每次要show這個快顯功能表的時候,總會出現如下異常:

java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
    …………
    
    上網查詢有的通報說是sun的jdk所包含的bug,也有其他解決方案。
    最終我這邊找到代碼中的問題是:程式沒有為JPopupMenu這個對象設定歸屬對象,由於之前的代碼沒有提交SVN,Local History中也沒有找回來,所以原始的問題代碼已經找不到了。
    印象中,當時編寫的時候,調用了JPopupMenu的某個設定歸屬對象的方法,設定了某個JPanel為JPopupMenu的歸屬對象,而在使用JPopupMenu的show方法展現該菜單時,卻使用的是某個JButton為JPopupMenu的invoker參數的值,可能因此而導致了上面的異常。
    解決方案就是,去除JPopupMenu與那個JPanel的歸屬關係的關聯代碼。
    
    由於沒有問題代碼,本文只是提供對類似問題的一種思路,之前另外一個系統中的Table的CellEditor使用JComboBox作為容器時也會出現這種問題,估計原因也是因為歸屬關係不明確造成,JComboBox中的快顯功能表無法定位而導致的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.