我有这个:
private void jOpenActionPerformed(java.awt.event.ActionEvent evt) {
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setApproveButtonText("Open");
fc.setMultiSelectionEnabled(true);
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File dr = fc.getSelectedFile();
if(!dr.isFile()){
JOptionPane.showMessageDialog(this,"Isn't file","eroare",JOptionPane.ERROR_MESSAGE);
}else if(!dr.canRead() || !dr.canExecute()){
JOptionPane.showMessageDialog(this,"You dont't have privileges","eroare",JOptionPane.ERROR_MESSAGE);
}else{
FileFilter filtruJPG = new FileFilter(){
@Override
public boolean accept(File file) {
return file.getName().endsWith("jpg");
}
};
File[] fisiere = dr.listFiles(filtruJPG);
if(fisiere.length==0){
JOptionPane.showMessageDialog(this,"Doesn't contain photos","eroare",JOptionPane.ERROR_MESSAGE);
}else{
poze = Arrays.asList(fisiere);
jLabel.setText("");
afisare();
}
}
}
}
我想从标签中将照片的文件名提取到文本字段中,但是当我打开照片时,它不会显示在标签上。 如果我选择DIRECTORIES_ONLY它正在工作,但我在文本字段中获取文件夹的文件名,
答案 0 :(得分:0)
尝试将file.getAbsolutePath()添加到JFileChooser。
File dr = fc.getSelectedFile().getAbsolutePath();
File dr = fc.getSelectedFile().getAbsolutePath();