从窗口中的按钮打开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