gpt4 book ai didi

Java:Bug:JFileChooser 仅有时出现

转载 作者:太空宇宙 更新时间:2023-11-04 13:17:19 25 4
gpt4 key购买 nike

我有一个方法来打开 JFileChooser 并允许用户选择一个文件以便稍后复制它的 URL。但是,JFileChooser 仅在我运行该程序时才显示(?)。

我不明白代码有什么问题。提前致谢。

More clearly: The UI of the JFileChooser does not show up.

    String readThisGlos = null;

JFrame parentFrame = new JFrame();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Choose");
int userSelection = fileChooser.showOpenDialog(parentFrame);
if (userSelection == JFileChooser.APPROVE_OPTION) {
File fileToSave = fileChooser.getSelectedFile();

readThisGlos = fileToSave.getAbsolutePath();
} else {
// Error
}
System.out.println(readThisGlos);
return readThisGlos;

编辑:我知道该方法正在运行,因为当我放置 System.out.println("//something");在该方法的开头,它有效。

If I put System.out.println("//something"); between fileChooser and int userSelection, the UI shows up.

最佳答案

我曾经遇到过类似的问题,我什至无法描述当时的沮丧。

试试这个:

  1. 重新启动计算机
  2. 在 Eclipse 中:文件 --> 重新启动
  3. 清理:C:\eclipse\eclipse.exe -vm "C:\Program Files\Java\jdk1.6.0_24\bin"-clean
  4. showOpenDialog(parentFrame) 更改为 showOpenDialog(null)(正如用户建议的那样,不必要的事情往往会产生问题)。
  5. 再次运行该程序。

关于Java:Bug:JFileChooser 仅有时出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33434972/

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