我有一個JFileChooser,通過調用ExportFileChooser.createAndShowGUI()方法的按鈕單擊啓動。當我關閉JFileChooser一個名爲ExportFileChooser的新的空窗口打開時,它可以正常工作,我該如何糾正這個問題,以便它不會啓動?JFileChooser關閉啓動新窗口
下面是代碼:
package org.annotationRoi3D.io;
import java.io.*;
import java.awt.*;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* This creates a dialog window for exporting
* and importing XML files.
*/
public class ExportFileChooser extends JPanel {
private static final long serialVersionUID = 1L;
public static File ExportFile;
JFileChooser fcExport;
public ExportFileChooser() {
super(new BorderLayout());
fcExport = new JFileChooser();
int returnValExport = fcExport.showSaveDialog(ExportFileChooser.this);
if (returnValExport == JFileChooser.APPROVE_OPTION) {
ExportFile = fcExport.getSelectedFile();
org.annotationRoi3D.io.ExportXML.OutputXML();
}
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event dispatch thread.
*/
public static void createAndShowGUI() {
//Create and set up the window.
JFrame frameExport = new JFrame("FileChooserExport");
frameExport.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add content to the window.
frameExport.add(new ExportFileChooser());
//Display the window.
frameExport.pack();
frameExport.setVisible(true);
}
}
謝謝
爲了更好地提供幫助,請將您的代碼發佈爲演示您的問題的[SSCCE](http://www.sscce.org)。這允許用戶複製/粘貼並重現您的問題。 –
那麼,這就是你的代碼所做的:它創建一個帶有'FileChooseExport'作爲標題的JFrame,並使其可見。爲什麼代碼會這樣做,如果你不想顯示一個框架? –
@JBNizet請做出回答 – MadProgrammer