Results 1 to 1 of 1
-
Demonstration of the DirectoryDialog class
Java Code:import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; /** * This class demonstrates the DirectoryDialog class */ public class ShowDirectoryDialog { /** * Runs the application */ public void run() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Directory Browser"); createContents(shell); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } /** * Creates the window contents * * @param shell the parent shell */ private void createContents(final Shell shell) { shell.setLayout(new GridLayout(6, true)); new Label(shell, SWT.NONE).setText("Directory:"); // Create the text box extra wide to show long paths final Text text = new Text(shell, SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; text.setLayoutData(data); // Clicking the button will allow the user // to select a directory Button button = new Button(shell, SWT.PUSH); button.setText("Browse..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { DirectoryDialog dlg = new DirectoryDialog(shell); // Set the initial filter path according // to anything they've selected or typed in dlg.setFilterPath(text.getText()); // Change the title bar text dlg.setText("SWT's DirectoryDialog"); // Customizable message displayed in the dialog dlg.setMessage("Select a directory"); // Calling open() will open and run the dialog. // It will return the selected directory, or // null if user cancels String dir = dlg.open(); if (dir != null) { // Set the text box to the new selection text.setText(dir); } } }); } /** * The application entry point * * @param args the command line arguments */ public static void main(String[] args) { new ShowDirectoryDialog().run(); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Demonstration of the ColorDialog class
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 07:56 PM -
Demonstration of the FontDialog class
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 07:55 PM -
Demonstration of Stack class in java.util package
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:33 PM -
TreeSet Demonstration
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:34 PM -
Demonstration of the Hashtable class, and an Enumeration
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks