java 文本框获取焦点 showopendialog冲突_java – jFileChooser.showOpenDialog()冻结应用程序..没有错误/异常..几件事情...

我在NetBeans 6.9.1中创建了一个Summarizer项目,因为我有一个“Browse”按钮,它应该在JFileChooser上打开一个打开的对话框.我看了看这里:very similar question on 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中从磁盘读取文件.

//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());

标签:java,swing,jfilechooser,showdialog

来源: https://codeday.me/bug/20190710/1420287.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值