從窗口中的按鈕打開JFileChooser後,File Chooser打開,然後原始窗口關閉。我想在用戶使用File Chooser時以及之後保持原始窗口始終打開。Java Swing:如何在關閉後保持父窗口打開JFileChooser
我的代碼:
// Code from the class that makes the original window that has the launch button
FilePicker filePicker = new FilePicker();
public void actionPerformed(ActionEvent e) {
txtImportLog.append("\nUser selecting file");
if (filePicker.canPick()) {
filePicker.init();
filePicker.getImportFile();
} else {
txtImportLog.append("\nCan't pick more files.");
}
}
});
// Code from the class that creates a FilePicker
//(yes, I know the getImportFile() and init() methods are setup badly, its just for
// testing right now
// Initialize - only should be called once
public void init() {
filePicker = new JFileChooser();
interval1 = 0;
interval2 = 0;
testFile = new File(""); // for testing. clearly.
}
// Get a file to import
public static File getImportFile() {
filePicker.setFileSelectionMode(JFileChooser.FILES_ONLY);
filePicker.showOpenDialog(filePicker);
return filePicker.getSelectedFile();
}
考慮提供一個[可運行示例](https://stackoverflow.com/help/mcve),它演示了您的問題。這會導致更少的混淆和更好的響應 – MadProgrammer 2014-11-21 01:09:28