在java中,有一个类叫JFileChooser, 通过他可以方便的创建一个文件打开保存对话框,但是有没有一个可以搜索目录的对话框,他不显示目录下面的文件,只以一个树形控件来显示目录。

解决方案 »

  1.   

    那么JFileChooser这个类能不能同时实现既可以选择文件,也可以选择目录?
      

  2.   

    可以的
    setFileSelectionMode
    public void setFileSelectionMode(int mode)
    Sets the JFileChooser to allow the user to just select files, just select directories, or select both files and directories. The default is JFilesChooser.FILES_ONLY. Parameters:
    mode - the type of files to be displayed: 
    JFileChooser.FILES_ONLY 
    JFileChooser.DIRECTORIES_ONLY 
    JFileChooser.FILES_AND_DIRECTORIES 
    Throws: 
    IllegalArgumentException - if mode is an illegal file selection mode
    See Also:
    getFileSelectionMode()