每次按下按钮时,是否会创建一个新的 JFileChooser 对象?是否可以处理它,或者java会自动为我做吗?
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);
}