CODEXE

SWT directory dialog

swt directory dialog

SWT Directory Dialog

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


public class Test {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Display d = new Display();
		Shell s = new Shell(d);
		s.setSize(200, 100);
		s.setLayout(new FillLayout(SWT.VERTICAL));
		//TODO: Add UI
		Text text = new Text(s, SWT.NONE);
		Button btn = new Button(s, SWT.NONE);
		btn.setText("Browse...");
		btn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				DirectoryDialog dlg = new DirectoryDialog(s);
				dlg.setFilterPath("D:/");
				dlg.setText("Directory Dialog");
				dlg.setMessage("Select a directory");
				String dir = dlg.open();//get the direction
				if (dir != null) {
					text.setText(dir);
				}
			}
		});
		//UI End
		s.open();

		while (!s.isDisposed()) {
		  if (!d.readAndDispatch())
			d.sleep();
		}
		d.dispose();
	  
	}
}