本文整理了Java中javax.swing.JFileChooser.showOpenDialog()
方法的一些代码示例,展示了JFileChooser.showOpenDialog()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFileChooser.showOpenDialog()
方法的具体详情如下:
包路径:javax.swing.JFileChooser
类名称:JFileChooser
方法名:showOpenDialog
暂无
代码示例来源:origin: stanfordnlp/CoreNLP
private void browseFiles() {
jfc.setDialogTitle("Open file");
int status = jfc.showOpenDialog(this);
if (status == JFileChooser.APPROVE_OPTION) {
urlTextField.setText(jfc.getSelectedFile().getPath());
openButton.setEnabled(true);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void actionPerformed(ActionEvent ae) {
final JFileChooser jfc = new JFileChooser();
final int response = jfc.showOpenDialog(LexerFrame.this);
if (response != JFileChooser.APPROVE_OPTION) {
return;
}
safeScanScript(jfc.getSelectedFile());
}
};
代码示例来源:origin: marytts/marytts
private void browseSoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseSoxActionPerformed
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
// System.out.println("Opening: " + file.getAbsolutePath());
tfSoxPath.setText(file.getAbsolutePath());
}
}// GEN-LAST:event_browseSoxActionPerformed
代码示例来源:origin: openmrs/openmrs-core
/**
* Do the stuff for this class (create the file)
*
* @throws Exception
*/
public static void main(String args[]) throws Exception {
System.out.println("Starting...");
String wd = "./test";
// choose the directory to open
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File(wd));
chooser.setMultiSelectionEnabled(true);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
File[] dirs = chooser.getSelectedFiles();
for (File directory : dirs) {
System.out.println("Doing migration on directory: " + directory.getAbsolutePath());
doMigration(directory);
}
}
}
代码示例来源:origin: log4j/log4j
/**
* Prompts the user for a file to load events from.
* @param aIgnore an <code>ActionEvent</code> value
*/
public void actionPerformed(ActionEvent aIgnore) {
LOG.info("load file called");
if (mChooser.showOpenDialog(mParent) == JFileChooser.APPROVE_OPTION) {
LOG.info("Need to load a file");
final File chosen = mChooser.getSelectedFile();
LOG.info("loading the contents of " + chosen.getAbsolutePath());
try {
final int num = loadFile(chosen.getAbsolutePath());
JOptionPane.showMessageDialog(
mParent,
"Loaded " + num + " events.",
"CHAINSAW",
JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
LOG.warn("caught an exception loading the file", e);
JOptionPane.showMessageDialog(
mParent,
"Error parsing file - " + e.getMessage(),
"CHAINSAW",
JOptionPane.ERROR_MESSAGE);
}
}
}
代码示例来源:origin: magefree/mage
private void btnImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportActionPerformed
String lastFolder = MageFrame.getPreferences().get("lastImportFolder", "");
if (!lastFolder.isEmpty()) {
fcImportDeck.setCurrentDirectory(new File(lastFolder));
int ret = fcImportDeck.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fcImportDeck.getSelectedFile();
MageFrame.getDesktop().setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
代码示例来源:origin: stackoverflow.com
JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
chooser.showOpenDialog(frame);
File[] files = chooser.getSelectedFiles();
if(files.length >= 2) {
compare(readFileAsList(files[0]), readFileAsList(files[1]));
}
代码示例来源:origin: stackoverflow.com
JFileChooser saveFile = new JFileChooser();
saveFile.showSaveDialog(null);
JFileChooser openFile = new JFileChooser();
openFile.showOpenDialog(null);
代码示例来源:origin: stackoverflow.com
import java.io.File;
import javax.swing.JFileChooser;
public class ShowDirectoriesOnly {
public static void main(String[] args) {
JFileChooser fileChooser = new JFileChooser( "." );
fileChooser.setControlButtonsAreShown( false );
fileChooser.setFileFilter( new FolderFilter() );
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.showOpenDialog(null);
}
private static class FolderFilter extends javax.swing.filechooser.FileFilter {
@Override
public boolean accept( File file ) {
return file.isDirectory();
}
@Override
public String getDescription() {
return "We only take directories";
}
}
}
代码示例来源:origin: marytts/marytts
private void browseSoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseSoxActionPerformed
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
// System.out.println("Opening: " + file.getAbsolutePath());
tfSoxPath.setText(file.getAbsolutePath());
}
}// GEN-LAST:event_browseSoxActionPerformed
代码示例来源:origin: cmusphinx/sphinx4
static public void getFilename(String title, int type) {
int returnVal;
fileChooser.setDialogTitle(title);
fileChooser.setCurrentDirectory(file);
fileChooser.setDialogType(type);
if (type == JFileChooser.OPEN_DIALOG) {
returnVal = fileChooser.showOpenDialog(jframe);
} else {
returnVal = fileChooser.showSaveDialog(jframe);
}
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fileChooser.getSelectedFile();
filename = file.getAbsolutePath();
prefs.put(FILENAME_PREFERENCE, filename);
}
}
代码示例来源:origin: magefree/mage
fcSelectDeck.setCurrentDirectory(new File(lastFolder));
int ret = fcSelectDeck.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fcSelectDeck.getSelectedFile();
file = new File(lastFolder);
代码示例来源:origin: EngineHub/WorldEdit
public static File showOpenDialog(String[] exts) {
JFileChooser dialog = new JFileChooser();
if (exts != null) {
dialog.setFileFilter(new ExtensionFilter(exts));
}
int returnVal = dialog.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
return dialog.getSelectedFile();
}
return null;
}
代码示例来源:origin: stanfordnlp/CoreNLP
public File getFile(boolean open) {
File file = null;
int returnVal;
if (open) {
returnVal = fileChooser.showOpenDialog(frame);
} else {
returnVal = fileChooser.showSaveDialog(frame);
}
if(returnVal == JFileChooser.APPROVE_OPTION) {
file = fileChooser.getSelectedFile();
if (open && !checkFile(file)) { file = null; }
}
return file;
}
代码示例来源:origin: stackoverflow.com
JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
chooser.showOpenDialog(frame);
File[] files = chooser.getSelectedFiles();
代码示例来源:origin: marytts/marytts
private void browseInputDirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseInputDirActionPerformed
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
// System.out.println("Opening: " + file.getAbsolutePath());
tfInputDir.setText(file.getAbsolutePath());
}
}// GEN-LAST:event_browseInputDirActionPerformed
代码示例来源:origin: magefree/mage
private void btnBrowseImageLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseImageLocationActionPerformed
int returnVal = fc.showOpenDialog(PreferencesDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
txtImageFolderPath.setText(file.getAbsolutePath());
}
}//GEN-LAST:event_btnBrowseImageLocationActionPerformed
代码示例来源:origin: checkstyle/checkstyle
@Override
public void actionPerformed(ActionEvent event) {
final JFileChooser fileChooser = new JFileChooser(model.getLastDirectory());
final FileFilter filter = new JavaFileFilter();
fileChooser.setFileFilter(filter);
final int returnCode = fileChooser.showOpenDialog(MainFrame.this);
if (returnCode == JFileChooser.APPROVE_OPTION) {
final File file = fileChooser.getSelectedFile();
openFile(file);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public File getFile(boolean open) {
File file = null;
int returnVal;
if (open) {
returnVal = fileChooser.showOpenDialog(frame);
} else {
returnVal = fileChooser.showSaveDialog(frame);
}
if(returnVal == JFileChooser.APPROVE_OPTION) {
file = fileChooser.getSelectedFile();
if (open && !checkFile(file)) { file = null; }
}
return file;
}
代码示例来源:origin: marytts/marytts
private void browseOutputDirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseOutputDirActionPerformed
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
// System.out.println("Opening: " + file.getAbsolutePath());
tfOutputDir.setText(file.getAbsolutePath());
}
}// GEN-LAST:event_browseOutputDirActionPerformed
内容来源于网络,如有侵权,请联系作者删除!