Microsoft SDK for Java

OpenFileDialog Class

Encapsulates the Save As common dialog box control that allows the user to open a file.

Component 
  |
  +--CommonDialog 
     |
     +--FileDialog 
        |
        +--OpenFileDialog

package com.ms.wfc.ui

public class OpenFileDialog
extends
FileDialog

Remarks

The following example sets options for an Open dialog box, displays the dialog box, and saves the names of the files the user selects in a string array:

private void btnOpen_click(Object source, Event e)
{
   OpenFileDialog ofd = new OpenFileDialog();
   ofd.setDefaultExt("java");   //sets the default extension
   ofd.setFilter("Java files (*.java)|*.java|All files
    (*.*)|*.*"); //sets the file filter
//Sets the filter that will be initially selected.
   ofd.setFilterIndex(1);  
//Sets the initial directory.
   ofd.setInitialDir("c:\\program files");  
   int dlgResult = ofd.showDialog();
   if (dlgResult == DialogResult.OK) {
//Gets the names of the files the user chose
      String[] fnames = ofd.getFileNames(); 
   }

© 1999 Microsoft Corporation. All rights reserved. Terms of use.