Welcome to the user guide for the JDirectoryChooser Swing Component. This guide will help to get you started with this powerful component, designed to provide you and your users with a convenient way of choosing directories from your Java applications.
![]()
There are a total of 6 ways to create the JDirectoryChooser. The simplest constructor will create the chooser dialog with the default "FileSystemView" - the object used to access your file system and get system icons. This chooser will start looking at the root of your system.
JDirectoryChooser myDirChooser = new JDirectoryChooser();
If you want the chooser to point at a particular directory, you have 2 different constructors to choose from: one of which takes a File, and one takes a String parameter.
File dir = new File("C:\\");
JDirectoryChooser myDirChooser = new JDirectoryChooser(dir);
or
JDirectoryChooser myDirChooser = new JDirectoryChooser("C:\\");
For more advanced uses, you can also specify the FileSystemView object you want to use.

There are 5 main areas of the JDirectoryChooser dialog that you can configure - all of this configuration should be performed before the dialog is displayed.
You set the title of the window using the following method:
myDirChooser.setTitle("Insert Title Here...");
The message text appears above the directory chooser tree, underneath the dialog title.
myTips.setMessageText("Select directory");
The 3 control buttons on the chooser dialog each have 3 things that you can change - the button text, the button mnemonic and the tool tip text.
myDirChooser.setOKButtonText("OK");
myDirChooser.setOKButtonMnemonic('O');
myDirChooser.setOKButtonToolTipText("Press to accept the currently selected directory");
Here are the 3 methods used to configure the "Cancel" button:
myDirChooser.setOKButtonText("OK");
myDirChooser.setOKButtonMnemonic('O');
myDirChooser.setOKButtonToolTipText("Press to accept the currently selected directory");
Here are the 3 methods used to configure the "Make Directory" button:
myDirChooser.setMakeDirectoryButtonText("Make New Folder");
myDirChooser.setMakeDirectoryButtonMnemonic('M');
myDirChooser.setMakeDirectoryButtonToolTipText("Press to create a new folder under the current folder");
Once your JDirectoryChooser has been configured, you are ready to display it to your users. This is done using just one simple method call.
myTips.showDialog(myFrame);
This will construct and display the directory chooser window. Note the Frame parameter - this can be null if you like, otherwise it should be the parent window of the chooser. The dialog will be centered around that frame.
The return parameter of the showDialog method indicates which button the user pressed to close the dialog - either OK or CANCEL. Based on this, you can decide your next course of action. For example:
if (myTips.showDialog(myFrame)==JDirectoryChooser.APPROVE_OPTION) {
File selectedFile = myTips.getCurrentDirectory();
// And proceed from here...
}
The 3 possible return values are APPROVE_OPTION, CANCEL_OPTION or ERROR_OPTION - the same as defined by the JFileChooser.
Like most of the SyGem Swing Components, the JDirectoryChooser has been created as a JavaBean, making it simple to use in conjunction with your favourite Java IDE. All you need to do is import the JDirectoryChooser JAR file into the IDE, and it should become available in the component palette of your choice. Please refer to the instruction manual for your IDE for more details on using and importing JavaBeans.
![]()
I hope you enjoy using the JDirectoryChooser - if you need any help using this or any of our components, please email us: jdirectorychooser@sygem.com