gpt4 book ai didi

java - 如何处置 JFileChooser

转载 作者:行者123 更新时间:2023-11-30 04:19:29 25 4
gpt4 key购买 nike

每次按下按钮时,它都会创建一个新的 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);
}

最佳答案

Java 使用垃圾收集器自动处理未使用的内存,所以是的。它将自动处理您的 JFileChooser 对象。

也是的,每次按下按钮时,如果调用buttonPressed,将创建一个新的JFileChooser。这是可以接受的。

关于java - 如何处置 JFileChooser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17455641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com