java.awt.FileDialog.getFiles()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中java.awt.FileDialog.getFiles()方法的一些代码示例,展示了FileDialog.getFiles()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileDialog.getFiles()方法的具体详情如下:
包路径:java.awt.FileDialog
类名称:FileDialog
方法名:getFiles

FileDialog.getFiles介绍

暂无

代码示例

代码示例来源:origin: redwarp/9-Patch-Resizer

private void displayImagePicker() {
 fileDialog.setVisible(true);
 File[] files = fileDialog.getFiles();
 if (files != null) {
  createScaleJobs(files);
 }
}

代码示例来源:origin: chewiebug/GCViewer

public void actionPerformed(final ActionEvent e) {
  if(OSXSupport.isOSX()) {
    // there is no way to show a checkbox on the native dialog so
    // open a new window instead
    FileDialog dialog = new FileDialog(gcViewer, LocalisationHelper.getString("fileopen_dialog_title"), FileDialog.LOAD);
    dialog.setMultipleMode(true);
    dialog.setVisible(true);
    // dialog.setFilenameFilter doesn't do much on OSX
    openFiles(dialog.getFiles(), false);
    dialog.dispose();
    return;
  }
  openFileView.setShowAddCheckBox(gcViewer.getSelectedGCDocument() != null);
  // TODO SWINGWORKER: open at last openposition (directory)
  final int val = openFileView.showOpenDialog(gcViewer);
  if (val == JFileChooser.APPROVE_OPTION) {
    openFiles(openFileView.getSelectedFiles(), openFileView.isAddCheckBoxSelected());
  }
}

代码示例来源:origin: stackoverflow.com

FileDialog fd = new FileDialog(new JFrame());
fd.setVisible(true);
File[] f = fd.getFiles();
if(f.length > 0){
  System.out.println(fd.getFiles()[0].getAbsolutePath());
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * @param temporary path to copy to new location
 * @param message   displayed message in save file dialog pop up
 */
private void copyFile(Path temporary, String message) {
  loadDialog.setMode(FileDialog.SAVE);
  loadDialog.setTitle(message);
  loadDialog.setVisible(true);
  File[] files = loadDialog.getFiles();
  if (files.length > 0) {
    File file = files[0];
    Path path = Paths.get(file.toURI());
    try {
      Files.copy(temporary, path, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
      LOGGER.log(Level.SEVERE, e.getMessage());
    }
  }
}

代码示例来源:origin: stackoverflow.com

@Test
public void performsSaveAsWhenNetHasNoFile() {
  SaveAsAction saveAsAction = new SaveAsAction(null, null);
  FileDialog mockFileDialog = mock(FileDialog.class);
  Controller mockController = mock(Controller.class);
  Net mockNet = mock(Net.class);

  NetName normalName = new NormalNetName("");
  when(mockNet.getName()).thenReturn(normalName);

  File file = new File("test.xml");
  when(mockFileDialog.getFiles()).thenReturn(new File[]{file});

  // these steps are crucial
  saveAsAction.setFileDialog(mockFileDialog);
  saveAsAction.setController(mockController);

  // test
  saveAsAction.actionPerformed(null);

  verify(mockController).saveAsFile(file);
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Loads the transition and state binary files into the member variables
 */
private void loadBinaryFiles() {
  loadDialog.setMode(FileDialog.LOAD);
  loadDialog.setTitle("Load transitions file");
  loadDialog.setVisible(true);
  File[] files = loadDialog.getFiles();
  if (files.length > 0) {
    File file = files[0];
    binaryTransitions = Paths.get(file.toURI());
    transitionFieldLabel.setText(file.getName());
  } else {
    return;
  }
  loadDialog.setTitle("Load states file");
  loadDialog.setVisible(true);
  File[] statesFiles = loadDialog.getFiles();
  if (statesFiles.length > 0) {
    File file = statesFiles[0];
    binaryStates = Paths.get(file.toURI());
    stateFieldLabel.setText(file.getName());
  } else {
    LOGGER.log(Level.INFO, "No file loaded");
  }
}

代码示例来源:origin: sarahtattersall/PIPE

/**
   * When this action is performed it shows the file dialog and processes the file selected for loading
   * @param e event 
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    fileChooser.setVisible(true);
    for (File file : fileChooser.getFiles()) {
      if (file.exists() && file.isFile() && file.canRead()) {
        try {
          applicationController.createNewTabFromFile(file);
        } catch (UnparsableException e1) {
          GuiUtils.displayErrorMessage(null, e1.getMessage());
        }
      } else {
        String message = "File \"" + file.getName() + "\" does not exist.";
        JOptionPane.showMessageDialog(null, message, "Warning", JOptionPane.WARNING_MESSAGE);
      }
    }
  }
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Opens the file dialog and saves the selected Petri net into lastLoadedPetriNet
 * for use when calculating the state space exploration
 */
private void loadData() {
  loadDialog.setMode(FileDialog.LOAD);
  loadDialog.setTitle("Select petri net");
  loadDialog.setVisible(true);
  File[] files = loadDialog.getFiles();
  if (files.length > 0) {
    File path = files[0];
    try {
      petriNetNameLabel.setText(path.getName());
      PetriNetReader petriNetIO = new PetriNetIOImpl();
      lastLoadedPetriNet = petriNetIO.read(path.getAbsolutePath());
    } catch (JAXBException | FileNotFoundException e) {
      LOGGER.log(Level.SEVERE, e.getMessage());
    }
  }
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Performs a save as operation. A save as chooses a file to save the Petri net to
 */
protected final void saveAsOperation() {
  fileDialog.setVisible(true);
  File[] files = fileDialog.getFiles();
  if (files.length != 0) {
    File file = files[0];
    saveNet(ensureExtension(file));
  }
}

代码示例来源:origin: igniterealtime/Spark

public void sendFileTo(ContactItem item) {
  FileDialog fileChooser = getFileChooser(SparkManager.getMainWindow(), Res.getString("title.select.file.to.send"));
  if (defaultDirectory != null)
  {
    fileChooser.setDirectory( defaultDirectory.getAbsolutePath() );
  }
  fileChooser.setVisible(true);
  final File[] files = fileChooser.getFiles();
  if ( files.length == 0) {
    // no selection
    return;
  }
  File file = files[0]; // Single-file selection is used. Using the first array item is safe.
  if (file.exists()) {
    defaultDirectory = file.getParentFile();
    sendFile( file, item.getJid() );
  }
}

代码示例来源:origin: igvteam/igv

public static File[] chooseMultiple(String title, File initialDirectory, final FilenameFilter filter) {
  File[] files = null;
  if (Globals.IS_MAC && !Globals.IS_JWS) {
    FileDialog fd = getNativeChooser(title, initialDirectory, null, filter, JFileChooser.FILES_ONLY, LOAD);
    if (fd.isMultipleMode()) {
      fd.setVisible(true);
      files = fd.getFiles();
    }
  }
  //Files will be an empty array if user cancelled dialog,
  //null if there was a problem with the native dialog
  if (files == null) {
    files = chooseMultipleSwing(title, initialDirectory, filter);
  }
  return files;
}

代码示例来源:origin: fiji/Trainable_Segmentation

imageFiles = fd.getFiles();
if( null == imageFiles || imageFiles.length == 0 )
  return;

代码示例来源:origin: sc.fiji/Trainable_Segmentation

imageFiles = fd.getFiles();
if( null == imageFiles || imageFiles.length == 0 )
  return;

代码示例来源:origin: igniterealtime/Spark

public void finished() {
    FileDialog fileChooser = SparkManager.getTransferManager().getFileChooser(SparkManager.getChatManager().getChatContainer().getChatFrame(), Res.getString("title.select.file.to.send"));
    if (SparkManager.getTransferManager().getDefaultDirectory() != null)
    {
      fileChooser.setDirectory(SparkManager.getTransferManager().getDefaultDirectory().getAbsolutePath());
    }
    fileChooser.setVisible(true);
    final File[] files = fileChooser.getFiles();
    if ( files.length == 0) {
      // no selection
      return;
    }
    File file = files[0]; // Single-file selection is used. Using the first array item is safe.
    if (file.exists()) {
      SparkManager.getTransferManager().setDefaultDirectory(file.getParentFile());
      SparkManager.getTransferManager().sendFile(file, ((ChatRoomImpl)chatRoom).getParticipantJID());
    }
  }
};

代码示例来源:origin: eu.mihosoft.vrl/vrl

File[] files = fd.getFiles();
if (files != null) {
  setSelectedFiles(files);

相关文章