本文整理汇总了Java中javax.swing.JFileChooser.getSelectedFile方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.getSelectedFile方法的具体用法?Java JFileChooser.getSelectedFile怎么用?Java JFileChooser.getSelectedFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.getSelectedFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importPreferencesDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Shows a file dialog from which to import preferences for biases from the
* tree.
*/
public void importPreferencesDialog() {
JFileChooser chooser = new JFileChooser();
XMLFileFilter filter = new XmlAedatFileFilter();
String lastFilePath = prefs.get("BiasgenFrame.lastFile", defaultFolder);
lastFile = new File(lastFilePath);
chooser.setFileFilter(filter);
chooser.setCurrentDirectory(lastFile);
int retValue = chooser.showOpenDialog(this);
if (retValue == JFileChooser.APPROVE_OPTION) {
try {
lastFile = chooser.getSelectedFile();
importPreferencesFromFile(lastFile);
} catch (Exception fnf) {
log.warning(fnf.toString());
}
}
// resend(); // shouldn't be necessary with the batch edit start/end in biasgen.importPreferences
}
示例2: browseIcon
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private URL browseIcon( ImagePreview preview ) {
URL res = null;
JFileChooser chooser = UIUtil.getIconFileChooser();
int ret = chooser.showDialog(this, NbBundle.getMessage(getClass(), "LBL_Select")); // NOI18N
if (ret == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
res = Utilities.toURI(file).toURL();
preview.setImage(new ImageIcon(res));
setModified();
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
}
}
return res;
}
示例3: selectPortfolioDirectory
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static File selectPortfolioDirectory(JFrame frame) {
// Create a file chooser
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setLocale(new Locale("fi", "FI"));
int returnVal = fc.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
return file;
}
return null;
}
示例4: jBtnBrowseActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void jBtnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnBrowseActionPerformed
jRbnFilesystem.setSelected(false);
jRbnFilesystem.setSelected(true);
enableControls();
JFileChooser chooser = new JFileChooser(previousDirectory);
chooser.setMultiSelectionEnabled(false);
chooser.setAcceptAllFileFilterUsed(false);
chooser.addChoosableFileFilter(WSDL_FILE_FILTER);
chooser.setFileFilter(WSDL_FILE_FILTER);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File wsdlFile = chooser.getSelectedFile();
jTxtLocalFilename.setText(wsdlFile.getAbsolutePath());
previousDirectory = wsdlFile.getPath();
}
}
示例5: openJVDFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Opens a .jvd file, parse it and fill given drawing model with elements
* from opened file.
*
* @param model
* Drawing model.
* @param frame
* Parent frame.
* @return Opened file.
*/
public static File openJVDFile(DrawingModel model, JVDraw frame) {
JFileChooser fc = new JFileChooser("./");
fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(new FileNameExtensionFilter(".jvd", "jvd"));
int status = fc.showOpenDialog(frame);
if (status == JFileChooser.OPEN_DIALOG) {
File file = fc.getSelectedFile();
if (!Files.isRegularFile(file.toPath())) {
return null;
}
model.clear();
readJVDFile(file, model);
return file;
}
return null;
}
示例6: onBrowse
import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected void onBrowse(JTextField txt) {
File oldFile = FileUtil.normalizeFile(new File(txt.getText()));
JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(Repository.class, "ACSD_BrowseCertFile"), oldFile); // NOI18N
fileChooser.setDialogTitle(NbBundle.getMessage(Repository.class, "Browse_title")); // NOI18N
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.showDialog(this.getPanel(), NbBundle.getMessage(Repository.class, "OK_Button")); // NOI18N
File f = fileChooser.getSelectedFile();
if (f != null) {
txt.setText(f.getAbsolutePath());
}
}
示例7: save
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private boolean save() {
boolean fileSaved = false;
if (tabbedPane.getSelectedIndex() == 0)
isoConfig.parseConfigToXML();
else
isoConfig.parseXmlToConfig(this);
if (txtFilePath.getText().equals("")) {
JFileChooser file = new JFileChooser();
file.setAcceptAllFileFilterUsed(false);
file.setFileFilter(new FileNameExtensionFilter("xml files (*.xml)", "xml"));
if (lastCurrentDirectory != null)
file.setCurrentDirectory(lastCurrentDirectory);
if (file.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
lastCurrentDirectory = file.getSelectedFile();
txtFilePath.setText(file.getSelectedFile().getAbsolutePath());
if (txtFilePath.getText().indexOf(".xml") < 0) txtFilePath.setText(txtFilePath.getText() +".xml");
}
}
isoConfig.saveFile(this, txtFilePath.getText());
fileSaved = (isoConfig.getXmlFilePath() != null);
if (!fileSaved)
JOptionPane.showMessageDialog(this, "You must inform a file to save.");
return fileSaved;
}
示例8: loadImageList
import javax.swing.JFileChooser; //导入方法依赖的package包/类
void loadImageList() {
JFileChooser fc = new JFileChooser(recordedPath);
int res = fc.showOpenDialog(this);
if (res == JFileChooser.APPROVE_OPTION) {
File f = fc.getSelectedFile();
recordedPath = f.getParent();
if (!IOTool.isTextFile(f)) {
// not a readable text file
JOptionPane.showMessageDialog(this,
String.format("\"%s\" \nis not a txt file.", f.getAbsolutePath()).toString(), "Not a txt file",
JOptionPane.WARNING_MESSAGE);
} else {
// read
ArrayList<String> imgList = IOTool.readText(f);
if (imgList == null) {
// read failed
JOptionPane.showMessageDialog(this,
String.format("\"%s\" \ncannot be properly read.", f.getAbsolutePath()).toString(),
"Reading failed", JOptionPane.WARNING_MESSAGE);
} else {
pathImgPair = IOTool.filterImageList(imgList, this);
if (pathImgPair.size() == 0) {
pathImgPair = null;
return;
}
fillImageNameTable();
leftTableSelectedRow = 0;
imgListTH.setSelectedRow(leftTableSelectedRow);
freezeReadImageListBtn();
}
}
}
}
示例9: saveAsExcel
import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected void saveAsExcel(Iterator it) {
JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
ExcelFileFilter eff = new ExcelFileFilter();
jfc.setFileFilter(eff);
File f=new File("PDB_Export.xls");
jfc.setSelectedFile(f);
do {
int c = jfc.showSaveDialog(null);
if (c==jfc.CANCEL_OPTION||c==jfc.ERROR_OPTION) return;
f = jfc.getSelectedFile();
if (f.exists()) {
c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
if (c==JOptionPane.OK_OPTION) break;
if (c==JOptionPane.CANCEL_OPTION) return;
}
} while (f.exists());
try {
WritableWorkbook wb = Workbook.createWorkbook(f);
WritableSheet sheet = wb.createSheet("First Sheet", 0);
int r = 0;
while (it.hasNext()) {
String[] split = it.next().toString().split("\\t");
for (int i = 0; i < split.length; i++)
sheet.addCell( new Label(i,r,split[i]) );
r++;
}
wb.write();
wb.close();
} catch (Exception ex){
}
}
示例10: saveFileDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
File saveFileDialog(File file) {
FileFilter fFileFilter = new FileFilter() {
@Override
public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(".csv") || f.isDirectory();
}
@Override
public String getDescription() {
return "Comma delimited (*.csv)";
}
};
JFileChooser fc = new JFileChooser(Defaults.getWorkingPath());
// Set filter for Java source files.
fc.setFileFilter(fFileFilter);
// Set to a default name for save.
fc.setSelectedFile(file);
// Open chooser dialog
int result = fc.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION) {
return null;
} else if (result == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
if (file.exists()) {
int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.CANCEL_OPTION) {
return null;
}
}
return file;
} else {
return null;
}
}
示例11: getFilePath
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static String getFilePath()
{
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.showDialog(new JLabel(), "确定");
return jfc.getSelectedFile() == null ? null
: jfc.getSelectedFile().getAbsolutePath();
}
示例12: loadMenuItemActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void loadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadMenuItemActionPerformed
JFileChooser fileChooser = new JFileChooser();
String lastFilePath = prefs.get("FilterFrame.lastFile", defaultFolder); // TODO seems to be same as for biases, should default to filterSettings folder of jAER
lastFile = new File(lastFilePath);
XMLFileFilter fileFilter = new XMLFileFilter();
fileChooser.addChoosableFileFilter(fileFilter);
fileChooser.setCurrentDirectory(lastFile); // sets the working directory of the chooser
int retValue = fileChooser.showOpenDialog(this);
if (retValue == JFileChooser.APPROVE_OPTION) {
File f = fileChooser.getSelectedFile();
loadFile(f);
}
}
示例13: openAEInputFileDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Called when user asks to open data file file dialog.
*/
@Override
public void openAEInputFileDialog() {
// try{Thread.currentThread().sleep(200);}catch(InterruptedException e){}
float oldScale = viewer.chipCanvas.getScale();
fileChooser = new JFileChooser();
// new TypeAheadSelector(fileChooser);
//com.sun.java.plaf.windows.WindowsFileChooserUI;
// fileChooser.addKeyListener(new KeyAdapter() {
// public void keyTyped(KeyEvent e){
// System.out.println("keycode="+e.getKeyCode());
// }
// });
// System.out.println("fileChooser.getUIClassID()="+fileChooser.getUIClassID());
// KeyListener[] keyListeners=fileChooser.getKeyListeners();
ChipDataFilePreview preview = new ChipDataFilePreview(fileChooser, viewer.getChip());
// from book swing hacks
new FileDeleter(fileChooser, preview);
fileChooser.addPropertyChangeListener(preview);
fileChooser.setAccessory(preview);
String lastFilePath = AEViewer.prefs.get("AEViewer.lastFile", "");
// get the last folder
viewer.lastFile = new File(lastFilePath);
// fileChooser.setFileFilter(datFileFilter);
IndexFileFilter indexFileFilter = new IndexFileFilter();
fileChooser.addChoosableFileFilter(indexFileFilter);
DATFileFilter datFileFilter = new DATFileFilter();
fileChooser.addChoosableFileFilter(datFileFilter);
if (lastFilter == null) {
fileChooser.setFileFilter(datFileFilter);
} else {
fileChooser.setFileFilter(lastFilter);
}
fileChooser.setCurrentDirectory(viewer.lastFile);
// sets the working directory of the chooser
// boolean wasPaused=isPaused();
setPaused(true);
try {
int retValue = fileChooser.showOpenDialog(viewer);
if (retValue == JFileChooser.APPROVE_OPTION) {
lastFilter = fileChooser.getFileFilter();
try {
viewer.lastFile = fileChooser.getSelectedFile();
if (viewer.lastFile != null) {
viewer.recentFiles.addFile(viewer.lastFile);
}
startPlayback(viewer.lastFile);
} catch (IOException fnf) {
log.warning(fnf.toString());
}
} else {
preview.showFile(null);
}
} catch (GLException e) {
log.warning(e.toString());
preview.showFile(null);
}
fileChooser = null;
// viewer.chipCanvas.setScale(oldScale);
// restore persistent scale so that we don't get tiny size on next startup
setPaused(false);
}
示例14: allPlatformSaveAs
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
*
* @param parentFrame
* @param dialogTitle
* @param directory
* @param fileExtension
* @param fractionFileName
* @param nonMacFileFilter
* @return
*/
public static File allPlatformSaveAs(
Frame parentFrame,
String dialogTitle,
String directory,
final String fileExtension,
String fractionFileName,
FileFilter nonMacFileFilter) {
File selectedFile;
JFileChooser fc = new JFileChooser();
fc.setSelectedFile(new File(directory + File.separator + fractionFileName));
fc.setFileFilter(nonMacFileFilter);
fc.setDialogTitle(dialogTitle);
// Show save dialog; this method does not return until the dialog is closed
int result = fc.showSaveDialog(new Frame());
if (result == JFileChooser.APPROVE_OPTION) {
selectedFile = fc.getSelectedFile();
// check for already exists
int response = 0;
if (selectedFile.exists()) {
// Modal dialog with OK/cancel and a text field
response = JOptionPane.showConfirmDialog(null,
new String[]{"The file exists.",
"Do you want to replace it?"
},
"ET Redux Warning",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.NO_OPTION) {
selectedFile = null;
}
}
} else {
selectedFile = null;
}
return selectedFile;
}
示例15: importServers
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static void importServers(GuiMultiplayer guiMultiplayer)
{
JFileChooser fileChooser =
new JFileChooser(WurstFolders.SERVERLISTS.toFile())
{
@Override
protected JDialog createDialog(Component parent)
throws HeadlessException
{
JDialog dialog = super.createDialog(parent);
dialog.setAlwaysOnTop(true);
return dialog;
}
};
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.addChoosableFileFilter(
new FileNameExtensionFilter("TXT files", "txt"));
int action = fileChooser.showOpenDialog(FrameHook.getFrame());
if(action == JFileChooser.APPROVE_OPTION)
try
{
File file = fileChooser.getSelectedFile();
BufferedReader load = new BufferedReader(new FileReader(file));
int i = 0;
for(String line = ""; (line = load.readLine()) != null;)
{
i++;
guiMultiplayer.savedServerList.addServerData(
new ServerData("Grief me #" + i, line, false));
guiMultiplayer.savedServerList.saveServerList();
guiMultiplayer.serverListSelector.setSelectedSlotIndex(-1);
guiMultiplayer.serverListSelector
.updateOnlineServers(guiMultiplayer.savedServerList);
}
load.close();
guiMultiplayer.refreshServerList();
}catch(IOException e)
{
e.printStackTrace();
MiscUtils.simpleError(e, fileChooser);
}
}