我有一個小問題,一個JDialog,它儘管我所做的一切交易完成後留下一個空架。我一直很長,以找到一個解決方案,不幸的是,這關閉的JDialog留下一個空架
daughterWindow.dispatchEvent(new WindowEvent(validation, WindowEvent.WINDOW_CLOSING));
也不
daughterWindow.setVisible(false);
daughterWindow.dispose();
也不是這一個最有可能幫助我
WindowAdapter adapter = (WindowAdapter)jdialog.getWindowListeners()[0];
adapter.windowClosing(new WindowEvent((Window)jdialog, WindowEvent.WINDOW_CLOSING));
,因爲一個ClassCastException的最後一個拋出。
異常在線程 「AWT-EventQueue的-0」 java.lang.ClassCastException:javax.swing.SwingUtilities中的$ SharedOwnerFrame不能轉換到java.awt.event.WindowAdapter中
這裏是我的代碼,也許有人可以給我一個提示。
JDialog daughterWindow = new JDialog();
daughterWindow.setModal(true);
daughterWindow.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
daughterWindow.getContentPane().setLayout(new BoxLayout(daughterWindow.getContentPane(), BoxLayout.Y_AXIS));
UIManager.put("FileChooser.readOnly", Boolean.TRUE);
JFileChooser open = new JFileChooser();
File rsc = new File(System.getProperty("user.dir") + "\\rsc\\");
if(!rsc.exists()) rsc.mkdir();
open.setCurrentDirectory(new File(System.getProperty("user.dir") + "\\rsc\\"));
open.setDialogTitle("Ordner mit der Datenbank auswählen");
open.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(open.showOpenDialog(daughterWindow) == JFileChooser.APPROVE_OPTION){
UIManager.put("FileChooser.readOnly", Boolean.FALSE);
setValidateAccessWindowLayout(open.getSelectedFile());
daughterWindow.dispatchEvent(new WindowEvent(daughterWindow, WindowEvent.WINDOW_CLOSING));
} else{
UIManager.put("FileChooser.readOnly", Boolean.FALSE);
daughterWindow.dispatchEvent(new WindowEvent(daughterWindow, WindowEvent.WINDOW_CLOSING));
}
daughterWindow.setResizable(false);
daughterWindow.pack();
daughterWindow.setVisible(true);
And a screen of the problem
預先感謝您!
UPDATE: 簽出無明顯不必要投第三個選項,但沒有很好的幫助。
WindowListener adapter = daughterWindow.getWindowListeners()[0];
adapter.windowClosing(new WindowEvent(daughterWindow, WindowEvent.WINDOW_CLOSING));
爲了更好地幫助更快,發佈[MCVE]或[短的,獨立的,正確的示例](http://www.sscce.org/)。所有的 –