Class FolderChooser

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class FolderChooser extends JFileChooser
FolderChooser provides a simple mechanism for the user to choose a folder.

In addition to supporting the basic folder choosing function, it also supports create new folder, delete an existing folder. Another useful feature is recent list. It allows you to set a list of recent selected folders so that user can choose them directly instead of navigating to it in the file system tree.

The following code pops up a folder chooser for user to choose a folder.

    FolderChooser chooser = new FolderChooser();
    int returnVal = chooser.showOpenDialog(parent);
    if(returnVal == FolderChooser.APPROVE_OPTION) {
       System.out.println("You chose to open this file: " +
            chooser.getSelectedFile().getName());
    }
 
See Also:
  • Field Details

  • Constructor Details

    • FolderChooser

      public FolderChooser()
    • FolderChooser

      public FolderChooser(String currentDirectoryPath)
    • FolderChooser

      public FolderChooser(File currentDirectory)
    • FolderChooser

      public FolderChooser(FileSystemView fsv)
    • FolderChooser

      public FolderChooser(File currentDirectory, FileSystemView fsv)
    • FolderChooser

      public FolderChooser(String currentDirectoryPath, FileSystemView fsv)
  • Method Details

    • getRecentList

      public List<String> getRecentList()
      Gets recent selected folder list. The element in the list is File.
      Returns:
      the recent selected folder list.
    • setRecentList

      public void setRecentList(List<String> recentList)
      Sets the recent folder list. The element in the list should be File. Property change event on PROPERTY_RECENTLIST will be fired when recent folder list is changed.
      Parameters:
      recentList - the recent folder list.
    • updateUI

      public void updateUI()
      Resets the UI property to a value from the current look and feel.
      Overrides:
      updateUI in class JFileChooser
      See Also:
    • getUIClassID

      public String getUIClassID()
      Returns a string that specifies the name of the L&F class that renders this component.
      Overrides:
      getUIClassID in class JFileChooser
      Returns:
      the string "FolderChooserUI"
      See Also:
    • getSelectedFolder

      public File getSelectedFolder()
      Returns the selected folder. This can be set either by the programmer via setSelectedFolder or by a user action, such as selecting the folder from a 'folder tree' in the UI.
      Returns:
      the selected folder in the folder tree
      See Also:
    • setSelectedFolder

      public void setSelectedFolder(File selectedFolder)
      Sets the selected folder.

      Property change event JFileChooser.SELECTED_FILE_CHANGED_PROPERTY will be fired when a new folder is selected.
      Parameters:
      selectedFolder - the selected folder
      See Also:
    • setNavigationFieldVisible

      public void setNavigationFieldVisible(boolean navigationFieldVisible)
      Sets the navigation text fields visibility.
      Parameters:
      navigationFieldVisible - if true, the navigation text field is displayed; otherwise it is hidden.
    • isNavigationFieldVisible

      public boolean isNavigationFieldVisible()
      Determines whether the navigation text field is visible.
      Returns:
      true if the navigation text field is visible; otherwise false.
    • getAvailableButtons

      public int getAvailableButtons()
      Get the visibilities of each buttons on the title bar of dockable frame.
      Returns:
      the visibilities of each buttons. It's a bit wise OR of values specified at BUTTON_XXX.
    • setAvailableButtons

      public void setAvailableButtons(int availableButtons)
      Set the visibilities of each buttons on the title bar of dockable frame.
      Parameters:
      availableButtons - the visibilities of each buttons. It's a bit wise OR of values specified at BUTTON_XXX.
    • isRecentListVisible

      public boolean isRecentListVisible()
      Get the visibility of the recent list combobox.
      Returns:
      the visibility of the combobox.
    • setRecentListVisible

      public void setRecentListVisible(boolean recentListVisible)
      Set the visibility of the recent list combobox.
      Parameters:
      recentListVisible - the visibility of the combobox
    • setFileFilter

      public void setFileFilter(FileFilter filter)
      Overrides:
      setFileFilter in class JFileChooser
    • getFileComparator

      public Comparator<File> getFileComparator()
      Gets the comparator that will be used to compare the folders displayed in the FolderChooser. This comparator will determine the order of the folders. It returns null by default.
      Returns:
      the Comparator.
    • setFileComparator

      public void setFileComparator(Comparator<File> fileComparator)
      Sets the comparator that will be used to compare the folders displayed in the FolderChooser. This comparator will determine the order of the folders. For example, you can use AlphanumFileComparator to sort the folder alphanum-ly.
      Parameters:
      fileComparator - a new Comparator.