javax.swing.JFileChooser.showDialog()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(221)

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

JFileChooser.showDialog介绍

暂无

代码示例

代码示例来源:origin: pmd/pmd

@Override
  public void actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser(rootDirectoryField.getText());
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fc.showDialog(frame, "Select");
    if (fc.getSelectedFile() != null) {
      rootDirectoryField.setText(fc.getSelectedFile().getAbsolutePath());
    }
  }
}

代码示例来源:origin: skylot/jadx

public void openFile() {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setAcceptAllFileFilterUsed(true);
  String[] exts = {"apk", "dex", "jar", "class", "zip", "aar", "arsc"};
  String description = "supported files: " + Arrays.toString(exts).replace('[', '(').replace(']', ')');
  fileChooser.setFileFilter(new FileNameExtensionFilter(description, exts));
  fileChooser.setToolTipText(NLS.str("file.open_action"));
  String currentDirectory = settings.getLastOpenFilePath();
  if (!currentDirectory.isEmpty()) {
    fileChooser.setCurrentDirectory(new File(currentDirectory));
  }
  int ret = fileChooser.showDialog(mainPanel, NLS.str("file.open_title"));
  if (ret == JFileChooser.APPROVE_OPTION) {
    settings.setLastOpenFilePath(fileChooser.getCurrentDirectory().getPath());
    openFile(fileChooser.getSelectedFile());
  }
}

代码示例来源:origin: marytts/marytts

private void jMenuItem_OpenActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem_OpenActionPerformed
  // Allow user to choose a different voice (prompt set) without exiting the tool
  // Create a file chooser
  final JFileChooser openDialog = new JFileChooser();
  // Set the current directory to the voice currently in use
  openDialog.setCurrentDirectory(getVoiceFolderPath());
  openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  int result = openDialog.showDialog(AdminWindow.this, "Open Voice");
  if (result == JFileChooser.APPROVE_OPTION) {
    File voice = openDialog.getSelectedFile();
    setVoiceFolderPath(voice); // Set to the selected the voice folder path
    Test.output("Open voice: " + voice);
    setupVoice();
  } else {
    Test.output("Open command cancelled.");
  }
}// GEN-LAST:event_jMenuItem_OpenActionPerformed

代码示例来源:origin: skylot/jadx

private void saveAll(boolean export) {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fileChooser.setToolTipText(NLS.str("file.save_all_msg"));
  String currentDirectory = settings.getLastSaveFilePath();
  if (!currentDirectory.isEmpty()) {
    fileChooser.setCurrentDirectory(new File(currentDirectory));
  }
  int ret = fileChooser.showDialog(mainPanel, NLS.str("file.select"));
  if (ret == JFileChooser.APPROVE_OPTION) {
    JadxArgs decompilerArgs = wrapper.getArgs();
    decompilerArgs.setExportAsGradleProject(export);
    if (export) {
      decompilerArgs.setSkipSources(false);
      decompilerArgs.setSkipResources(false);
    } else {
      decompilerArgs.setSkipSources(settings.isSkipSources());
      decompilerArgs.setSkipResources(settings.isSkipResources());
    }
    settings.setLastSaveFilePath(fileChooser.getCurrentDirectory().getPath());
    ProgressMonitor progressMonitor = new ProgressMonitor(mainPanel, NLS.str("msg.saving_sources"), "", 0, 100);
    progressMonitor.setMillisToPopup(0);
    wrapper.saveAll(fileChooser.getSelectedFile(), progressMonitor);
  }
}

代码示例来源:origin: RipMeApp/ripme

JFileChooser jfc = new JFileChooser(Utils.getWorkingDirectory());
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = jfc.showDialog(null, "select directory");
if (returnVal != JFileChooser.APPROVE_OPTION) {
  return;
JFileChooser jfc = new JFileChooser(Utils.getWorkingDirectory());
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = jfc.showDialog(null, "Open");
if (returnVal != JFileChooser.APPROVE_OPTION) {
  return;

代码示例来源:origin: magefree/mage

protected void playerLoadDeck() {
  String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", "");
  if (!lastFolder.isEmpty()) {
    fcSelectDeck.setCurrentDirectory(new File(lastFolder));
  }
  int ret = fcSelectDeck.showDialog(this, "Select Deck");
  if (ret == JFileChooser.APPROVE_OPTION) {
    File file = fcSelectDeck.getSelectedFile();
    this.txtPlayerDeck.setText(file.getPath());
    try {
      MageFrame.getPreferences().put("lastDeckFolder", file.getCanonicalPath());
    } catch (IOException ex) {
    }
  }
  fcSelectDeck.setSelectedFile(null);
}

代码示例来源:origin: magefree/mage

protected String playerLoadDeck() {
  if (fcSelectDeck == null) {
    fcSelectDeck = new JFileChooser();
    fcSelectDeck.setAcceptAllFileFilterUsed(false);
    fcSelectDeck.addChoosableFileFilter(new DeckFilter());
  }
  String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", "");
  if (!lastFolder.isEmpty()) {
    fcSelectDeck.setCurrentDirectory(new File(lastFolder));
  }
  int ret = fcSelectDeck.showDialog(this, "Select Deck");
  if (ret == JFileChooser.APPROVE_OPTION) {
    File file = fcSelectDeck.getSelectedFile();
    return (file.getPath());
  }
  return "";
}

代码示例来源:origin: RaiMan/SikuliX2

if (fchooser.showDialog(parent, btnApprove) != JFileChooser.APPROVE_OPTION) {
 return null;

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

b.setLayoutY(50);
b.setOnMouseClicked(new EventHandler<MouseEvent>() {

    public void handle(MouseEvent event) {
      JFileChooser fileChooser = new JFileChooser();
      fileChooser.showDialog(javafxPanel, null);

    }
  });

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

private String filePath;

// ...

public void actionPerformed(ActionEvent e)
{
  JFileChooser chooser=new JFileChooser();
  int ret = chooser.showDialog(null, "Open file");
  if(ret == JFileChooser.APPROVE_OPTION)
  {
    File file = chooser.getSelectedFile();
    filePath = file.getPath();
  }
}

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

final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

// final File dir = new File("/ProjectName/mp3Directory");
File dir = null;
int selection = fc.showDialog(null, "Open");
if(selection == JFileChooser.APPROVE_OPTION) {
  dir = fc.getSelectedFile();
} else {
  System.out.print("Please select a directory to continue");
  System.exit(0);
}

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

JFileChooser jfc = new JFileChooser();
 jfc.showDialog(null,"Please Select the File");
 jfc.setVisible(true);
 File filename = jfc.getSelectedFile();
 System.out.println("File name "+filename.getName());

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-jboss4

private String browseInstallLocation(){
  String insLocation = null;
  JFileChooser chooser = getJFileChooser();
  int returnValue = chooser.showDialog(SwingUtilities.getWindowAncestor(this),
      NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooseButton")); //NOI18N
  
  if(returnValue == JFileChooser.APPROVE_OPTION){
    insLocation = chooser.getSelectedFile().getAbsolutePath();
  }
  return insLocation;
}

代码示例来源:origin: it.tidalwave.netbeans/it-tidalwave-netbeans-actions

@Override
 public void runOnConfirmation (final JFileChooser fileChooser,
                 final Component component,
                 final Notifier notifier)
  {
   if (fileChooser.showDialog(component, "Ok") == JFileChooser.APPROVE_OPTION)
    {
     notifier.notify(fileChooser.getSelectedFile());
    }
  }
}

代码示例来源:origin: tinyMediaManager/tinyMediaManager

@Override
public int showDialog(Component parent, String approveButtonText) throws HeadlessException {
 if (!JAVAFX_AVAILABLE) {
  return super.showDialog(parent, approveButtonText);
 }
 return showOpenDialog(parent);
}

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

import javax.imageio.*;

...

JFileChooser fileOpen = new JFileChooser();

// Get array of available formats
String[] suffices = ImageIO.getReaderFileSuffixes();

// Add a file filter for each one
for (int i = 0; i < suffices.length; i++) {
  FileFilter filter = new FileNameExtensionFilter(suffices[i] + " files", suffices[i]);
  fileOpen.addChoosableFileFilter(filter);
}

// Show dialog
int ret = fileOpen.showDialog(null, "Open file");

代码示例来源:origin: edu.toronto.cs.savant/savant-core

@Override
  public void actionPerformed(ActionEvent e) {
    fc.setDialogType(JFileChooserDialogType);
    int result = fc.showDialog(null, null);
    if (result == JFileChooser.CANCEL_OPTION || result == JFileChooser.ERROR_OPTION) {
      return;
    }
    setPath(fc.getSelectedFile().getAbsolutePath());
  }
});

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-wizards

private void iconButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iconButtonActionPerformed
  JFileChooser chooser = WizardUtils.getIconFileChooser(iconField.getText());
  int ret = chooser.showDialog(this, getMessage("LBL_Select")); // NOI18N
  if (ret == JFileChooser.APPROVE_OPTION) {
    iconField.setText(chooser.getSelectedFile().getAbsolutePath());
    updateData();
  }
}//GEN-LAST:event_iconButtonActionPerformed

代码示例来源:origin: chatty/chatty

/**
 * Open a JFileChooser to select a directory to use.
 */
private void chooseDirectory() {
  JFileChooser chooser = new JFileChooser(getCurrentPath().toFile());
  chooser.setAcceptAllFileFilterUsed(false);
  chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  if (chooser.showDialog(parentComponent, Language.getString("settings.chooseFolder")) == JFileChooser.APPROVE_OPTION) {
    setSettingValue(chooser.getSelectedFile().getPath());
  }
}

代码示例来源:origin: org.activecomponents.jadex/jadex-runtimetools-swing

/**
 *  Load settings from file.
 *  Asks the user for a file name.
 */
protected void	loadSettings()
{
  if(getFileChooser().showDialog(this, "Load Settings")==JFileChooser.APPROVE_OPTION)
  {
    File file = getFileChooser().getSelectedFile();
    controlcenter.loadSettings(file);
  }
}

相关文章

JFileChooser类方法