簡體   English   中英

單擊按鈕可使JInternalFrame出現一次,即使最小化也是如此

[英]button click to make JInternalFrame appear once even when minimized

下面的代碼使JFrame內的JDesktopPane上彈出JInternalFrame

JInternalPane adf = new JInternalpane();
JDesktopPane.add(adf);
adf.show();

但是當InternalFrame被圖標化或在DesktopPane上仍可見時,再次單擊使顯示InternalFrame的Action_Button,則再次彈出相同類型的另一個InternalFrame。 並保持點擊次數不斷地彈出。
請如何生成代碼,以便在單擊按鈕時首先應檢查internalFrame是否已圖標化,然后使其再次可見。 而不是彈出另一個內部框架。
我正在將NetBeans IDE與JDK 8一起使用。
當我右鍵單擊按鈕,選擇“事件”,然后執行“操作”時,將執行button_action,到目前為止,我只編寫了此代碼。

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
JInternalPane adf = new JInternalpane();
JDesktopPane.add(adf);
adf.show();
// TODO add your handling code here:
        }

謝謝

您需要為內部框架保留一個實例變量,以便了解當前狀態。

然后,ActionListener中的代碼將類似於:

if (internalFrame == null) // not yet created
{
    internalFrame = new JInternalFrame(...);
    desktopPane.add( internalFrame );
    internalFrame.show();
}
else if (internal frame is iconified) // read the API for the method to use
{
    //  show the internal frame
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM