Java Tutorial/SWT/DirectoryDialog — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 15:19, 31 мая 2010

17. Creating the dialog and retrieving the selected directory

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();
  }
}





17. Customizing the Directory Selection Dialog: set title and message

  1. Call setText(), passing the desired text, to change what"s displayed in the title bar.
  2. Call setMessage(), passing your custom message, to change the message text.



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();
  }
}





17. Set Filter Path

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();
  }
}