问题描述
我正在尝试创建一个应用程序,在我单击某个按钮后,我需要一个文件选择器。问题是当我这样做时,在我选择我想要的文件或单击取消后,JFileChooser 再次打开。我一直在浏览一些页面,但似乎找不到解决方案。提前致谢。
这是我的代码:
FileInputStream imatgeUp = null;
File arxiu = null;
if (comanda.equals("cercaimatge")) {
JFileChooser pickPic = new JFileChooser();
pickPic.setFileFilter(new FileNameExtensionFilter("Archivos de imagen","jpg","jpeg","png"));
//int opcion = pickPic.showOpenDialog(addCar);
if (pickPic.showOpenDialog(addCar) == JFileChooser.APPROVE_OPTION) {
String ruta = pickPic.getSelectedFile().getAbsolutePath();
try {
arxiu = new File(ruta);
imatgeUp = new FileInputStream(arxiu);
Icon imatgeMostra = new ImageIcon(ruta);
imatgeEscollida.setIcon(imatgeMostra);
imatgeEscollida.setBounds(400,250,190,122);
addCar.add(imatgeEscollida);
UploadImage.upImage(con,imatgeUp);
frame.revalidate();
frame.repaint();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)