SWT/JFace 对话框

String enter = System.getProperty("line.separator")//系统中的回车

String seperator=File.separator//系统中"\"or"/"

//1.

DirectoryDialog dirDialog = new DirectoryDialog(composite.getShell());
  dirDialog.setFilterPath("D:\a"+seperator);
  String url = dirDialog.open();

//2.

FileDialog fileDialog = new FileDialog(composite.getShell());
  fileDialog.setFilterPath("D:\a"+seperator);
  fileDialog.setFilterExtensions(...);
  String url = fileDialog.open();

//3.

Shell shell=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

Image img=...;

MessageDialog messageDialog = new MessageDialog(shell,"Title", img,"xxxxxx?", MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
result = messageDialog.open();

MessageDialog.openError(Display.getCurrent().getActiveShell(),"xxx Error",“xxxxx”);

//4.

  MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_INFORMATION | SWT.OK | SWT.CANCEL);
  mb.setText("Title");
  mb.setMessage("xxx?");
  int result = mb.open();
  if (result == SWT.OK) {
   filePath = filePath.trim();
   Program program = Program.findProgram("pdf");//寻找相关的可执行程序
   if (filePath.endsWith(".doc")) {
    program = Program.findProgram("doc");
   } else if (filePath.endsWith(".xls")) {
    program = Program.findProgram("xls");
   }
   program.execute(filePath);
  }

 

你可能感兴趣的:(jface)