Java Code Examples for javax.swing.JFileChooser.showOpenDialog()

The following are Jave code examples for showing how to use showOpenDialog() of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Websocket-Smart-Card-Signer   File: SignUI.java   Source Code and License Vote up 7 votes
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;
}
 
Example 2
Project: incubator-netbeans   File: BuildContextVisual.java   Source Code and License Vote up 6 votes
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());
    }
}
 
Example 3
Project: incubator-netbeans   File: FileChooserBuilder.java   Source Code and License Vote up 6 votes
/**
 * 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;
    }

}
 
Example 4
Project: incubator-netbeans   File: PickIconAction.java   Source Code and License Vote up 6 votes
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);
    }
}
 
Example 5
Project: javaportfolio   File: PortfolioDocument.java   Source Code and License Vote up 6 votes
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;
	}
 
Example 6
Project: poi-visualizer   File: POITopMenuBar.java   Source Code and License Vote up 6 votes
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();
	}
}
 
Example 7
Project: incubator-netbeans   File: PanelProjectLocationExtSrc.java   Source Code and License Vote up 6 votes
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());
        }
    }
}
 
Example 8
Project: Progetto-C   File: ParticleEditor.java   Source Code and License Vote up 5 votes
/**
 * 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());
	}
}
 
Example 9
Project: ramus   File: RSFViewer.java   Source Code and License Vote up 5 votes
/**
 * @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);
}
 
Example 10
Project: Equella   File: DialogUtils.java   Source Code and License Vote up 5 votes
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());
}
 
Example 11
Project: FaceAnnotationTool   File: MainFrame.java   Source Code and License Vote up 5 votes
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();

			}
		}

	}
}
 
Example 12
Project: sumo   File: CustomSafeReader.java   Source Code and License Vote up 5 votes
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;
}
 
Example 13
Project: incubator-netbeans   File: Selenium2Customizer.java   Source Code and License Vote up 5 votes
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();
    }
}
 
Example 14
Project: Equella   File: CLAConfigPanel.java   Source Code and License Vote up 5 votes
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);
		}
	}
}
 
Example 15
Project: bddproject   File: File.java   Source Code and License Vote up 5 votes
/**
* 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;
}
 
Example 16
Project: Mujeed-Arabic-Prolog   File: JFilePicker.java   Source Code and License Vote up 5 votes
@Override
public void actionPerformed(ActionEvent e) {
	// TODO Auto-generated method stub
	JFileChooser fileChooser = new JFileChooser();
	fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	//fileChooser.showOpenDialog(fileChooser);
	int status = fileChooser.showOpenDialog(null);
	if (status == JFileChooser.APPROVE_OPTION) 
		textField.setText(fileChooser.getSelectedFile().getAbsolutePath());	
	 else if (status == JFileChooser.CANCEL_OPTION) {
	    }
}
 
Example 17
Project: incubator-netbeans   File: SetUpRemotePlatform.java   Source Code and License Vote up 5 votes
private void buttonBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBrowseActionPerformed
    final String oldValue = keyFilePath.getText();
    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (oldValue != null) {
        chooser.setSelectedFile(new File(oldValue));
    }
    chooser.setDialogTitle(NbBundle.getMessage(SetUpRemotePlatform.class, "Title_Chooser_SelectKeyfile")); //NOI18N
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        keyFilePath.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 18
Project: Kaeon-FUSION   File: IO.java   Source Code and License Vote up 4 votes
public static String openAsString() {

		JFileChooser chooser = new JFileChooser();
		int returnVal = chooser.showOpenDialog(null);

		if(returnVal == JFileChooser.APPROVE_OPTION) {

			File file = chooser.getSelectedFile();

			return readAsString(file);
		}

		return null;
	}
 
Example 19
Project: openjdk-jdk10   File: MetalworksFrame.java   Source Code and License Vote up 4 votes
public void openDocument() {
    JFileChooser chooser = new JFileChooser();
    chooser.showOpenDialog(this);
}
 
Example 20
Project: SER316-Munich   File: EditTypeDialog.java   Source Code and License Vote up 4 votes
void setIconB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
    UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");
    
    JFileChooser chooser = new JFileChooser();
    chooser.setPreferredSize(new Dimension(550, 375));
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Choose icon file"));
    //chooser.setAcceptAllFileFilterUsed(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(
        new File(net.sf.memoranda.ui.AppFrame.class.getResource("resources/icons/mimetypes").getPath()));
    /*if (System.getProperty("os.name").startsWith("Win")) {
        chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.ICO));
        chooser.setCurrentDirectory(new File("C:\\Program Files"));
    }
    else */
    chooser.addChoosableFileFilter(new net.sf.memoranda.ui.htmleditor.filechooser.ImageFilter());
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            iconLabel.setIcon(new ImageIcon(chooser.getSelectedFile().getPath()));
       }
        catch (Exception ex) {
  //ex.printStackTrace();
 }
        finally {
            iconPath = chooser.getSelectedFile().getPath();
        }

    }
}