gpt4 book ai didi

java - 检测 JFileChooser 何时关闭

转载 作者:行者123 更新时间:2023-12-01 07:03:41 25 4
gpt4 key购买 nike

JFileChooser有一个方法addActionListener它接受 ActionListener当用户按下 JFileChooser 窗口底部的两个按钮之一时,将调用该函数。但是,正如我发现的那样,当用户通过单击选择器窗口标题栏中的关闭按钮(或使用操作系统的其他方法来关闭它)来关闭 JFileChooser 时,不会调用它。所以我的问题是:在这种情况下,JFileChooser 的创建者如何识别它何时被关闭?

最佳答案

你的意思是这样吗:

JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
// select file
} else if (result == JFileChooser.CANCEL_OPTION) {
// file chooser closed
}

关于java - 检测 JFileChooser 何时关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33463962/

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