演示FileDialog : 对话框 « SWT-JFace-Eclipse « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » SWT-JFace-Eclipse » 对话框屏幕截图 
演示FileDialog
演示FileDialog


//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner (rwarner@interspatial.com)
//Robert Harris (rbrt_harris@yahoo.com)

import java.io.File;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates FileDialog
 */
public class ShowFileDialog {
  // These filter names are displayed to the user in the file dialog. Note that
  // the inclusion of the actual extension in parentheses is optional, and
  // doesn't have any effect on which files are displayed.
  private static final String[] FILTER_NAMES = {
      "OpenOffice.org Spreadsheet Files (*.sxc)",
      "Microsoft Excel Spreadsheet Files (*.xls)",
      "Comma Separated Values Files (*.csv)""All Files (*.*)"};

  // These filter extensions are used to filter which files are displayed.
  private static final String[] FILTER_EXTS = "*.sxc""*.xls""*.csv""*.*"};

  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("File Dialog");
    createContents(shell);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }

  /**
   * Creates the contents for the window
   
   @param shell the parent shell
   */
  public void createContents(final Shell shell) {
    shell.setLayout(new GridLayout(5true));

    new Label(shell, SWT.NONE).setText("File Name:");

    final Text fileName = new Text(shell, SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    fileName.setLayoutData(data);

    Button multi = new Button(shell, SWT.PUSH);
    multi.setText("Open Multiple...");
    multi.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        // User has selected to open multiple files
        FileDialog dlg = new FileDialog(shell, SWT.MULTI);
        dlg.setFilterNames(FILTER_NAMES);
        dlg.setFilterExtensions(FILTER_EXTS);
        String fn = dlg.open();
        if (fn != null) {
          // Append all the selected files. Since getFileNames() returns only 
          // the names, and not the path, prepend the path, normalizing
          // if necessary
          StringBuffer buf = new StringBuffer();
          String[] files = dlg.getFileNames();
          for (int i = 0, n = files.length; i < n; i++) {
            buf.append(dlg.getFilterPath());
            if (buf.charAt(buf.length() 1!= File.separatorChar) {
              buf.append(File.separatorChar);
            }
            buf.append(files[i]);
            buf.append(" ");
          }
          fileName.setText(buf.toString());
        }
      }
    });

    Button open = new Button(shell, SWT.PUSH);
    open.setText("Open...");
    open.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        // User has selected to open a single file
        FileDialog dlg = new FileDialog(shell, SWT.OPEN);
        dlg.setFilterNames(FILTER_NAMES);
        dlg.setFilterExtensions(FILTER_EXTS);
        String fn = dlg.open();
        if (fn != null) {
          fileName.setText(fn);
        }
      }
    });

    Button save = new Button(shell, SWT.PUSH);
    save.setText("Save...");
    save.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        // User has selected to save a file
        FileDialog dlg = new FileDialog(shell, SWT.SAVE);
        dlg.setFilterNames(FILTER_NAMES);
        dlg.setFilterExtensions(FILTER_EXTS);
        String fn = dlg.open();
        if (fn != null) {
          fileName.setText(fn);
        }
      }
    });
  }

  /**
   * The application entry point
   
   @param args the command line arguments
   */
  public static void main(String[] args) {
    new ShowFileDialog().run();
  }
}


           
       
Related examples in the same category
1. TitleAreaDialog : MailDialog
2. 对话框窗口对话框窗口
3. 消息框消息框
4. 输入对话框输入对话框
5. 对话框的例子对话框的例子
6. 保存FileDialog
7. 如何创建自己的对话框类如何创建自己的对话框类
8. 演示FontDialog类演示FontDialog类
9. 演示ColorDialog级演示ColorDialog级
10. 演示DirectoryDialog级演示DirectoryDialog级
11. 显示自定义InputDialog级显示自定义InputDialog级
12. 消息框范例消息框范例
13. 对话范例
14. 窗口对话范例窗口对话范例
15. 颜色对话框颜色对话框
16. 文件对话框文件对话框
17. 字体对话框实例字体对话框实例
18. 是否图标消息框是否图标消息框
19. 打印对话框打印对话框
20. SWT对话框类SWT对话框类
21. 防止使用Escape键关闭SWT对话框防止使用Escape键关闭SWT对话框
22. 创建一个对话框,窗口(提示值)创建一个对话框,窗口(提示值)
23. 创建一个SWT对话框窗口创建一个SWT对话框窗口
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.