0
的每一個按鈕被按下時,它創建一個新的JFileChooser對象?是否有可能出售它,還是java的爲我做自動?如何處置JFileChooser中
public void buttonPressed(){
JFileChooser chooser = null;
LookAndFeel previousLF = UIManager.getLookAndFeel();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
chooser = new JFileChooser();
UIManager.setLookAndFeel(previousLF);
} catch (IllegalAccessException | UnsupportedLookAndFeelException | InstantiationException | ClassNotFoundException e) {}
File location = new File("C:\\");
chooser.setCurrentDirectory(location);
chooser.setDialogTitle("Select Your Directory");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
chooser.showOpenDialog(frame);
}
[嗯不同意(http://stackoverflow.com/questions/6309407/remove-top-level-container-on-runtime) – mKorbel
的時間量需要創建一個文件選擇器類是如此格言足夠螞蟻考慮使用惰性加載方法,,但保持創建的實例,如果你認爲它會被重用。如果連建立在過去的一個全球性和配置它需要 – MadProgrammer