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


Java JFileChooser.showOpenDialog方法代码示例

本文整理汇总了Java中javax.swing.JFileChooser.showOpenDialog方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.showOpenDialog方法的具体用法?Java JFileChooser.showOpenDialog怎么用?Java JFileChooser.showOpenDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JFileChooser的用法示例。


在下文中一共展示了JFileChooser.showOpenDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: showFileSelection

import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static List<Data> showFileSelection() throws Exception{
    List<Data> ret = new ArrayList<Data>();
    
    JFileChooser jfc = new JFileChooser();
    jfc.setMultiSelectionEnabled(true);
    
    jfc.setDialogTitle("Choose the files to sign");
    SignUtils.playBeeps(1);
    if(jfc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
        return null;
    
    File[] choosedFileList = jfc.getSelectedFiles();
    for(File file:choosedFileList){
        String id = file.getAbsolutePath();
        byte[] fileContent = IOUtils.readFile(file);
        ret.add(new Data(id, fileContent));
    }
    return ret;
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:20,代码来源:SignUI.java

示例2: buildContextButtonActionPerformed

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void buildContextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buildContextButtonActionPerformed
    FileChooserBuilder builder = FileChooserBuilder.create(fileSystem);
    JFileChooser fileChooser = builder.createFileChooser();
    fileChooser.setApproveButtonText(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.button")); // NOI18M
    fileChooser.setDialogTitle(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.dialogTitle")); // NOI18M
    fileChooser.setFileSelectionMode(0);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    String buildText = UiUtils.getValue(buildContextTextField);
    if (buildText != null) {
        fileChooser.setSelectedFile(new File(buildText));

    }
    if (fileChooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        buildContextTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:BuildContextVisual.java

示例3: showOpenDialog

import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
 * Show an open dialog with a file chooser set up according to the
 * parameters of this builder.
 * @return A file if the user clicks the accept button and a file or
 * folder was selected at the time the user clicked cancel.
 */
public File showOpenDialog() {
    JFileChooser chooser = createFileChooser();
    if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
        FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
        if( null != fileDialog ) {
            return showFileDialog(fileDialog, FileDialog.LOAD );
        }
    }
    chooser.setMultiSelectionEnabled(false);
    int dlgResult = chooser.showOpenDialog(findDialogParent());
    if (JFileChooser.APPROVE_OPTION == dlgResult) {
        File result = chooser.getSelectedFile();
        if (result != null && !result.exists()) {
            result = null;
        }
        return result;
    } else {
        return null;
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:FileChooserBuilder.java

示例4: performAction

import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected @Override void performAction(Node[] activatedNodes) {
    FileObject f = PickNameAction.findFile(activatedNodes);
    if (f == null) {
        return;
    }
    NbModuleProvider p = PickNameAction.findProject(f);
    if (p == null) {
        return;
    }
    FileObject src = p.getSourceDirectory();
    JFileChooser chooser = UIUtil.getIconFileChooser();
    chooser.setCurrentDirectory(FileUtil.toFile(src));
    if (chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    FileObject icon = FileUtil.toFileObject(chooser.getSelectedFile());
    // XXX might instead get WritableXMLFileSystem.cp and search for it in there:
    String iconPath = FileUtil.getRelativePath(src, icon);
    try {
        if (iconPath == null) {
            String folderPath;
            String layerPath = ManifestManager.getInstance(Util.getManifest(p.getManifestFile()), false).getLayer();
            if (layerPath != null) {
                folderPath = layerPath.substring(0, layerPath.lastIndexOf('/'));
            } else {
                folderPath = p.getCodeNameBase().replace('.', '/') + "/resources"; // NOI18N
            }
            FileObject folder = FileUtil.createFolder(src, folderPath);
            FileUtil.copyFile(icon, folder, icon.getName(), icon.getExt());
            iconPath = folderPath + '/' + icon.getNameExt();
        }
        f.setAttribute("iconBase", iconPath); // NOI18N
    } catch (IOException e) {
        Util.err.notify(ErrorManager.INFORMATIONAL, e);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:PickIconAction.java

示例5: 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

示例6: loadNewFile

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void loadNewFile() {
	final JFileChooser fc = new JFileChooser();
	fc.setCurrentDirectory(workingDir);
	final int returnVal = fc.showOpenDialog(this);
	if (returnVal != JFileChooser.APPROVE_OPTION) {
		return;
	}
	final File file = fc.getSelectedFile();
	workingDir = file.getParentFile();
	try {
		clearCurrentFile();
		appContext.getBean(TreeModelFileSource.class, treeRoot).load(file);
		treeModel.reload(treeRoot);
		POIMainFrame mainFrame = appContext.getBean(POIMainFrame.class);
		mainFrame.setFileTitle(file);
	} catch (TreeModelLoadException ex) {
		JOptionPane.showMessageDialog(this, ex.getMessage());
		clearCurrentFile();
	}
}
 
开发者ID:kiwiwings,项目名称:poi-visualizer,代码行数:21,代码来源:POITopMenuBar.java

示例7: browseProjectLocation

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void browseProjectLocation(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseProjectLocation
    // TODO add your handling code here:
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(NbBundle.getMessage(PanelSourceFolders.class, "LBL_NWP1_SelectProjectLocation")); // NOI18N
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    String path = this.projectLocation.getText();
    if (path.length() > 0) {
        File f = new File(path);
        File owner = f.getParentFile();
        if (owner.exists()) {
            chooser.setCurrentDirectory(owner);
        }
        if (f.exists()) {
            chooser.setSelectedFile(f);
        }
    }
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        if (file != null) {
            this.projectLocation.setText(FileUtil.normalizeFile(file).getAbsolutePath());
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:PanelProjectLocationExtSrc.java

示例8: loadBackground

import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
 * Load a background image to display behind the particle system
 */
private void loadBackground() {
	JFileChooser chooser = new JFileChooser(".");
	chooser.setDialogTitle("Open");
	int resp = chooser.showOpenDialog(this);
	if (resp == JFileChooser.APPROVE_OPTION) {
		game.setBackgroundImage(chooser.getSelectedFile());
	}
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:12,代码来源:ParticleEditor.java

示例9: main

import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {

    System.setProperty("user.ramus.application.name", "RSFViewerDemo");

    if (args.length < 1) {
        System.err.println("Usage: RSFViewer rsf_file		View rsf file");
        System.out.println("Show open dialog");
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileFilter() {

            @Override
            public String getDescription() {
                return "Ramus rsf files";
            }

            @Override
            public boolean accept(File f) {
                if (f.isFile()) {
                    return f.getName().toLowerCase().endsWith(".rsf");
                } else
                    return true;
            }
        });

        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            args = new String[]{chooser.getSelectedFile()
                    .getAbsolutePath()};
        } else {
            System.exit(0);
            return;
        }
    }

    Database database = FileDatabaseFactory
            .createDatabase(new File(args[0]));

    new RSFViewer(database.getEngine(null)).setVisible(true);
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:42,代码来源:RSFViewer.java

示例10: doDialog

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private static DialogResult doDialog(Component parent, boolean isOpenDialog, String title, FileFilter filter,
	boolean acceptAllFilter, File defaultFile)
{
	JFileChooser chooser = new JFileChooser(getDirectory());
	if( title != null )
	{
		chooser.setDialogTitle(title);
	}
	if( filter != null )
	{
		chooser.setFileFilter(filter);
	}
	if( defaultFile != null )
	{
		chooser.setSelectedFile(defaultFile);
	}
	if( !acceptAllFilter )
	{
		chooser.setAcceptAllFileFilterUsed(false);
	}

	int result = 0;
	if( isOpenDialog )
	{
		result = chooser.showOpenDialog(parent);
	}
	else
	{
		result = chooser.showSaveDialog(parent);
	}
	return new DialogResult(result, chooser.getSelectedFile(), chooser.getCurrentDirectory());
}
 
开发者ID:equella,项目名称:Equella,代码行数:33,代码来源:DialogUtils.java

示例11: 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

示例12: selectFile

import javax.swing.JFileChooser; //导入方法依赖的package包/类
public String selectFile(){
	String filePath=null;
	String folder=(String)pref.get(LAST_FOLDER,"");
	JFileChooser chooser=new JFileChooser(folder);
	int returnVal=chooser.showOpenDialog(frame);
	if (returnVal == JFileChooser.APPROVE_OPTION) {
           File file = chooser.getSelectedFile();
           filePath=file.getAbsolutePath();
           pref.put(LAST_FOLDER, file.getParentFile().getAbsolutePath());	
       }
	return filePath;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:13,代码来源:CustomSafeReader.java

示例13: bSeleniumServerJarActionPerformed

import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void bSeleniumServerJarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSeleniumServerJarActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileFilter(new FileNameExtensionFilter("Jar File", "jar"));
    chooser.setSelectedFile(new File(tfSeleniumServerJar.getText().trim()));
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        tfSeleniumServerJar.setText(chooser.getSelectedFile().getAbsolutePath());
        updateValidity();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:Selenium2Customizer.java

示例14: uploadFile

import javax.swing.JFileChooser; //导入方法依赖的package包/类
void uploadFile()
{
	JFileChooser chooser = new JFileChooser();
	chooser.setFileFilter(new FileFilter()
	{
		@Override
		public String getDescription()
		{
			return getString("agreement.filefilter"); //$NON-NLS-1$
		}

		@Override
		public boolean accept(File f)
		{
			if( f.isDirectory() )
			{
				return true;
			}
			String name = f.toString().toLowerCase();
			return name.endsWith(".zip") || name.endsWith(".htm") || name.endsWith(".html") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
				|| name.endsWith(".xsl") || name.endsWith(".xslt"); //$NON-NLS-1$ //$NON-NLS-2$
		}
	});

	final int returnVal = chooser.showOpenDialog(this);
	if( returnVal == JFileChooser.APPROVE_OPTION )
	{
		File selectedFile = chooser.getSelectedFile();
		if( selectedFile.getName().toLowerCase().endsWith(".zip") ) //$NON-NLS-1$
		{
			doZipUpload(selectedFile);
		}
		else
		{
			doSimpleUpload(selectedFile);
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:39,代码来源:CLAConfigPanel.java

示例15: selectAndReadFile

import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Use the readFile method with a JFileChooser interface to select the file to convert.
* @return The file convert in String
*/
public static String selectAndReadFile(){
    String ret = "";
    JFileChooser chooser = new JFileChooser("../ws/samples");
    java.util.Locale.setDefault(java.util.Locale.ENGLISH);
    chooser.setLocale(java.util.Locale.ENGLISH);
    chooser.setLocale(java.util.Locale.getDefault());
    chooser.updateUI();
    chooser.setFileFilter(new FileNameExtensionFilter("SQL file (*.sql)", "sql"));
    int returnVal = chooser.showOpenDialog(null);
    if(returnVal == JFileChooser.APPROVE_OPTION){
        ret = readFile(chooser.getSelectedFile().getAbsolutePath());
    }
    return ret;
}
 
开发者ID:mudcam,项目名称:bddproject,代码行数:19,代码来源:File.java


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