[英]JFileChooser.showOpenDialog not opening, and no error being thrown?
[英]jFileChooser.showOpenDialog() freezes the application..no error / exception..tried several things
我在NetBeans 6.9.1中創建了一個Summarizer項目,因為我有一個“Browse”按鈕,它應該在JFileChooser上打開一個打開的對話框。 我在這看了一下: stackoverflow上非常相似的問題
我的問題是一樣的,我嘗試設置當前目錄,該目錄在stackoverflow上嘗試了另一個類似的問題,但即使這樣也無法在我的PC上運行。
我仍然無法弄清楚我的錯誤到底是什么。 我認為事情沒有在EDT上運行也是同樣的錯誤。 我使用netbeans,代碼很大。 我無法找到在哪里更改EDT的事情。 所以我只發布它的相關部分。 請看看並告訴我如何解決我的問題?
private void cmdBrowseActionPerformed(java.awt.event.ActionEvent evt) {
jFileChooser1.setCurrentDirectory(new File("F:/BE-Project/Summarizer"));
jFileChooser1.setDialogTitle("Open File");
jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = jFileChooser1.showOpenDialog(Summarizer.this);
if (returnVal== JFileChooser.APPROVE_OPTION) {
try {
fin = jFileChooser1.getSelectedFile();
fileContents = Files.readFromFile(fin,"ISO-8859-1");
tAreafileContents.setText( fileContents );
txtInputFile.setText( fin.getAbsolutePath() + " -- " + fin.getName());
tAreafileContents.setCaretPosition(tAreafileContents.getDocument().getLength());
}
catch (Exception e) {
System.out.println(e);
}
}
else System.out.println("there is some error");
}
/* netbeans generated code */
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Summarizer().setVisible(true);
}
});
}
請告訴我是否需要任何其他代碼部分,請幫忙。 我現在正在撓頭。
我建議您的問題是在EDT中從磁盤讀取File
。
//this should be in a worker thread
fileContents = Files.readFromFile(fin,"ISO-8859-1");
//this then gets dumped back on the EDT
tAreafileContents.setText( fileContents );
txtInputFile.setText( fin.getAbsolutePath() + " -- " + fin.getName());
tAreafileContents.setCaretPosition(tAreafileContents.getDocument().getLength());
你確定只是一個JFileChooser問題嗎? 你的F:單位是硬盤,網絡共享,USB驅動器嗎? 如果不是,您可以嘗試將設備更換為硬盤嗎? 在netbeans和命令行中運行這些測試,讀取F:上的文件以及與F不同的其他一些單元
import java.io.*;
public class FileSize
{
public static void main(String [] args)
{
//String fileName = "F:/BE-Project/Summarizer/someFile.txt");
String fileName = "FileSize.java";
long size = new File(fileName).length();
System.out.println("size: " + size);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.