Class DirectoryChooser

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class DirectoryChooser extends JComponent
DirectoryChooser provides a simple mechanism for the user to choose a directory. The following pops up a directory chooser in the users home directory DirectoryChooser chooser = new DirectoryChooser(); int returnVal = chooser.showDialog(parent); if(returnVal == DirectoryChooser.APPROVE_OPTION) { System.out.println("You choosed directory : " + chooser.getSelectedFile().getName()); }
Author:
Bhupesh Jadhav
See Also:
  • Field Details

    • APPROVE_OPTION

      public static int APPROVE_OPTION
    • CANCEL_OPTION

      public static int CANCEL_OPTION
    • dialog

      protected JDialog dialog
    • folderLb

      protected JLabel folderLb
    • folderJt

      protected JTextField folderJt
    • directoryPane

      protected JScrollPane directoryPane
    • approveJb

      protected JButton approveJb
    • cancelJB

      protected JButton cancelJB
    • driveLb

      protected JLabel driveLb
    • drivesJcb

      protected JComboBox drivesJcb
    • directoryTree

      protected JTree directoryTree
    • option

      protected int option
    • panel

      protected JPanel panel
  • Constructor Details

    • DirectoryChooser

      public DirectoryChooser() throws MissingResourceException
      Construct a DirectoryChooser pointing to the last selected directory if any else to the users home directory
      Throws:
      MissingResourceException
    • DirectoryChooser

      public DirectoryChooser(String currentDirectoryPath) throws MissingResourceException
      Constructs a DirectoryChooser using the given path. Passing in a null string causes the DirectoryChooser to point to the user's home directory.
      Parameters:
      String - representing the directory to be selected
      Throws:
      MissingResourceException
  • Method Details

    • getLastDirectory

      public static File getLastDirectory()
      Returns:
      any previously selected directory as File object
    • getSelectedDirectory

      public File getSelectedDirectory()
      Gets the selected directory as an File object
      Returns:
      selected file
    • setSelectedDirectory

      public void setSelectedDirectory(File file)
      Sets the selected directory
      Parameters:
      File - to be selected
    • setDialogTitle

      public void setDialogTitle(String title)
      Sets the DirectoryChooser dialog title
      Parameters:
      String - title
    • showDialog

      public int showDialog(Component parent)
      Display the dialog
      Parameters:
      parent - - the parent component of the dialog, can be null
      Returns:
      the return state of the file chooser on popdown: DirectoryChooser.CANCEL_OPTION DirectoryChooser.APPROVE_OPTION
    • setApproveButtonToolTipText

      public void setApproveButtonToolTipText(String toolTipText)
      Sets the tooltip used in the ApproveButton
      Parameters:
      Tool - tip text
    • getApproveButtonToolTipText

      public String getApproveButtonToolTipText()
      Gets the tooltip used in ApproveButton
      Returns:
      Tool tip text
    • setApproveButtonMnemonic

      public void setApproveButtonMnemonic(char mnemonic)
      Sets the Mnemonic used in Approve Button
      Parameters:
      char -
    • getApproveButtonMnemonic

      public int getApproveButtonMnemonic()
      Gets the Mnemonic in Approve Button
      Returns:
      mnemonic
    • setApproveButtonText

      public void setApproveButtonText(String approveButtonText)
      Sets the Approve Button text
      Parameters:
      approve - button text
    • getApproveButtonText

      public String getApproveButtonText()
      Gets the text used in Approve Button
      Returns:
      approve button text
    • getPath

      protected TreePath getPath(File file)
      Returns:
      TreePath of the node identified by File "file"