waysun一路阳光

不轻易服输,不轻言放弃.--心是梦的舞台,心有多大,舞台有多大。踏踏实实做事,认认真真做人。

  BlogJava :: 首页 :: 新随笔 :: 联系 ::  :: 管理 ::
  167 随笔 :: 1 文章 :: 64 评论 :: 0 Trackbacks
1.目录选择框            
              JFileChooser chooser=new JFileChooser();
              chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
              int result=chooser.showOpenDialog(null);
              String fname=chooser.getName(chooser.getSelectedFile());
              System.out.println("fname--->"+fname);
              if(result==JFileChooser.APPROVE_OPTION)
              {
                 
                   String filePath=chooser.getSelectedFile().getPath();
                   System.out.println("filePath--->"+filePath);
                   if(filePath.endsWith(".xml"))
                   {
                       System.out.println("filePath--->"+filePath);
                   }
              }
Object[] options = { "OK", "CANCEL" };
              int results= JOptionPane.showOptionDialog(null, "是否保存?", "Warning",
              JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,null, options, options[0]);
              if(results==JOptionPane.OK_OPTION)
              {
                  doSave();
              }
              if(results==JOptionPane.NO_OPTION )
              {
                   doReturn();
              }
2.文件选择框
        javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
        chooser.showOpenDialog(null);
          String fname=chooser.getName(chooser.getSelectedFile());


posted on 2009-02-09 17:17 weesun一米阳光 阅读(2168) 评论(1)  编辑  收藏 所属分类: JAVA源码

评论

# re: java中的目录选择框和文件选择框【源】 2014-07-15 16:33 梁燕双栖
我要学java  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: