当前位置: 首页>>代码示例>>Java>>正文


Java JFileChooser.getSelectedFile方法代码示例

本文整理汇总了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
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:24,代码来源:BiasgenFrame.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:BasicBrandingPanel.java

示例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;
	}
 
开发者ID:skarna1,项目名称:javaportfolio,代码行数:14,代码来源:PortfolioDocument.java

示例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();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:AddWebServiceDlg.java

示例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;
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:27,代码来源:FIleFactory.java

示例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());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ConnectionType.java

示例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;
}
 
开发者ID:adelbs,项目名称:ISO8583,代码行数:33,代码来源:PnlMain.java

示例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();

			}
		}

	}
}
 
开发者ID:Microos,项目名称:FaceAnnotationTool,代码行数:37,代码来源:MainFrame.java

示例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){
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:35,代码来源:PDB.java

示例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;
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:41,代码来源:CustomDialog.java

示例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();
}
 
开发者ID:binjie09,项目名称:tttclass,代码行数:9,代码来源:CommonUtil.java

示例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);
           }
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:14,代码来源:FilterFrame.java

示例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);
    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:65,代码来源:AEPlayer.java

示例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;
}
 
开发者ID:CIRDLES,项目名称:Squid,代码行数:51,代码来源:FileHelper.java

示例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);
		}
}
 
开发者ID:Wurst-Imperium,项目名称:Wurst-MC-1.12-OF,代码行数:44,代码来源:ServerHook.java


注:本文中的javax.swing.JFileChooser.getSelectedFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。