我學會了使用NotifyDescriptor創建彈出對話框。我設計了一個帶有兩個大按鈕的JPanel,它們的讀數爲PURCHASE
和CASHOUT
,我使用的代碼顯示底部的另外兩個按鈕,它們的讀數爲Yes
和No
。我不想讓NotifyDescriptor將自己的按鈕放在屏幕上。我只是想讓我的按鈕在那裏,當我點擊一個自定義按鈕時,彈出窗口會關閉並存儲這個值(就像當點擊時點擊了yes
或no
時它是如何關閉窗口一樣)。我使用的代碼如下在Netbeans平臺中使用自定義NotifyDescriptor
// Create instance of your panel, extends JPanel... ChooseTransactionType popupSelector = new ChooseTransactionType(); // Create a custom NotifyDescriptor, specify the panel instance as a parameter + other params NotifyDescriptor nd = new NotifyDescriptor( popupSelector, // instance of your panel "Title", // title of the dialog NotifyDescriptor.YES_NO_OPTION, // it is Yes/No dialog ... NotifyDescriptor.QUESTION_MESSAGE, // ... of a question type => a question mark icon null, // we have specified YES_NO_OPTION => can be null, options specified by L&F, // otherwise specify options as: // new Object[] { NotifyDescriptor.YES_OPTION, ... etc. }, NotifyDescriptor.YES_OPTION // default option is "Yes" ); // let's display the dialog now... if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.YES_OPTION) { // user clicked yes, do something here, for example: System.out.println(popupSelector.getTRANSACTION_TYPE()); }
優秀!!這是我正在尋找..謝謝你! – Deepak 2012-04-25 02:00:31
歡迎您,祝您好運 – 2012-04-25 03:09:44