1 public class JFileChooserKnow
 2 {
 3 
 4     /**
 5      * @param args
 6      */
 7     public static void main(String[] args)
 8     {
 9         // TODO Auto-generated method stub
10         //文件选择器
11         JFileChooser chooser = new JFileChooser();
12         //设置文件过滤器
13         chooser.setFileFilter(new FileNameExtensionFilter("图片","gif","jpg","bmp"));
14         //获取用户的操作结果,是确认了,还是取消了
15         int choose = chooser.showOpenDialog(null);
16         //判断选择的结果
17         if(choose == JFileChooser.APPROVE_OPTION)
18         {
19             //获取文件路径
20             JOptionPane.showMessageDialog(null, chooser.getSelectedFile().getAbsolutePath());
21         }
22     }
23 
24 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-24
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2021-09-02
相关资源
相似解决方案