Java Tutorial/SWT/DirectoryDialog
17. Creating the dialog and retrieving the selected directory
<source lang="java">
import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class DirectoryDialogGetSelectedDirectory {
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); DirectoryDialog dlg = new DirectoryDialog(shell); String selectedDirectory = dlg.open(); System.out.println(selectedDirectory); display.dispose(); }
}</source>
17. Customizing the Directory Selection Dialog: set title and message
- Call setText(), passing the desired text, to change what"s displayed in the title bar.
- Call setMessage(), passing your custom message, to change the message text.
<source lang="java">
import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class DirectoryDialogTextMessage {
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); DirectoryDialog dlg = new DirectoryDialog(shell); dlg.setText("My Text"); dlg.setMessage("My Message"); String selectedDirectory = dlg.open(); System.out.println(selectedDirectory); display.dispose(); }
}</source>
17. Set Filter Path
<source lang="java">
import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class DirectoryDialogFilterPath {
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); DirectoryDialog dlg = new DirectoryDialog(shell); dlg.setFilterPath("C:/"); String selectedDirectory = dlg.open(); System.out.println(selectedDirectory); display.dispose(); }
}</source>