Example #1
0
  public void jButton1_actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(parent);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      jTextField1.setText(file.toString());
    }
  }
Example #2
0
  void doEditFilename() {
    // create the file open dialog
    final JFileChooser jf = new JFileChooser();

    // cancel multiple selections
    jf.setMultiSelectionEnabled(false);

    // set the start directory
    if (_lastDirectory != null) {
      jf.setCurrentDirectory(new File(_lastDirectory));
    } else {

      String val = "";

      // see if we have an old directory to retrieve
      val = Application.getThisProperty("RANGE_Directory");

      // give it a default value, if we have to
      if (val == null) val = "";

      // try to get the import directory
      jf.setCurrentDirectory(new File(val));
    }

    // open the dialog
    final int state = jf.showOpenDialog(null);

    // do we have a valid file?
    if (state == JFileChooser.APPROVE_OPTION) {
      // retrieve the filename
      final File theFile = jf.getSelectedFile();
      _theFilename = theFile.getPath();

      // retrieve the directory name
      _lastDirectory = theFile.getParent();

      // trigger a refresh
      refreshForm();
    } else if (state == JFileChooser.CANCEL_OPTION) {
      _theFilename = null;
    }
  }