List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:com.freedomotic.jfrontend.MainWindow.java
private void mnuOpenEnvironmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuOpenEnvironmentActionPerformed mnuSaveActionPerformed(null);/*from ww w.j a va 2s . c o m*/ final JFileChooser fc = new JFileChooser(Info.PATHS.PATH_DATA_FOLDER + "/furn/"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); File file = null; int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); LOG.info("Opening environment file \"{}\"", file.getAbsolutePath()); try { api.environments().init(file); setEnvironment(api.environments().findAll().get(0)); mnuSelectEnvironmentActionPerformed(null); } catch (RepositoryException e) { LOG.error(Freedomotic.getStackTraceInfo(e)); } setWindowedMode(); } else { LOG.info(i18n.msg("canceled_by_user")); } }
From source file:net.sourceforge.entrainer.gui.EntrainerFX.java
private void editXml() { JFileChooser xmlChooser = XmlEditor.getXmlFileChooser(); int val = xmlChooser.showOpenDialog(this); if (val == JFileChooser.APPROVE_OPTION) { showXmlEditor(xmlChooser.getSelectedFile()); }/*from ww w .j av a 2s. co m*/ }
From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java
private void menuItemFileOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemFileOpenActionPerformed final JFileChooser dlg = new JFileChooser(this.destinationFile); dlg.setFileFilter(Utils.JHX_FILE_FILTER); if (dlg.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { final File file = dlg.getSelectedFile(); loadFromFile(file);/*from w ww. j av a 2 s . c o m*/ } }
From source file:net.sourceforge.entrainer.gui.EntrainerFX.java
private void loadXml() { intervalMenu.removeAllIntervals();//from w w w.ja v a 2 s . c o m JFileChooser chooser = XmlEditor.getXmlFileChooser(); int val = chooser.showOpenDialog(this); if (val == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); if (f != null) { try { clearXmlFile(); readXmlFile(f.getName()); soundControlPane.setPlayingEntrainerProgram(true); } catch (Exception e) { GuiUtil.handleProblem(e); soundControlPane.setPlayingEntrainerProgram(false); } } } }
From source file:org.biojava.bio.view.MotifAnalyzer.java
public void runMethod(MotifFinder method) { final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new Filter("fasta")); fc.setDialogTitle("Select Sequence File (in FASTA format)"); int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = fc.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { try {/*w w w . java 2 s. c o m*/ final JFileChooser readDirectory = new JFileChooser(); readDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { Dataset dataset = (Dataset) datasetComboBox.getSelectedItem(); int type = datasetTypeComboBox.getSelectedIndex(); String fileName = (returnVal == JFileChooser.APPROVE_OPTION) ? fc.getSelectedFile().getCanonicalPath() : TompaDataset.getDatasetSequenceFileName(dataset); int i = Integer.parseInt(numOfMotifs.getText()); int w = Integer.parseInt(motifWidth.getText()); int t = Integer.parseInt(numOfTrials.getText()); OrganismCode organism = OrganismCode.getOrganism(organismType.getSelectedIndex()); log.info("Runninf method: " + method.name()); log.info("FileName: " + fileName); log.info("Outputfile: " + readDirectory.getSelectedFile().getCanonicalPath()); log.info("Dataset: " + dataset.name()); log.info("DatasetType: " + type); controller.runAndEvaluate(method, fileName, i, w, t, organism, dataset, readDirectory.getSelectedFile().getCanonicalPath()); displayCharts(); } } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(mainFrame, "An Error occured", "Error", JOptionPane.ERROR_MESSAGE); } } }
From source file:la2launcher.MainFrame.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try {//www . j av a 2s. co m JFileChooser fc; if (gamePath == null || gamePath.trim().equals("")) { fc = new JFileChooser(); } else { if (new File(gamePath).isDirectory()) { fc = new JFileChooser(gamePath); } else { fc = new JFileChooser(); } } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.showOpenDialog(this); File f = fc.getSelectedFile(); if (f != null) { gamePath = f.getAbsolutePath(); jTextField2.setText(gamePath); } boolean systemFound = false; for (String fname : f.list()) { if (fname.toUpperCase().equals("SYSTEM")) { systemFound = true; break; } } if (!systemFound) { JOptionPane.showMessageDialog(this, "? system. . ? ?."); } } catch (Exception ex) { logg(""); logg(ex); } }
From source file:grupob.TipoProceso.java
private void seleccionarGeneralActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seleccionarGeneralActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Seleccionar Carpeta"); int returnValue = fileChooser.showOpenDialog(null); File selectedFile = fileChooser.getSelectedFile(); String ext = FilenameUtils.getExtension(selectedFile.getName()); if (ext.compareTo("xlsx") != 0) { JOptionPane.showMessageDialog(null, "Debe seleccionar un archivo excel."); } else {/*from w w w . j a va 2 s . c om*/ textConfGeneral.setText("" + selectedFile); } // Recorte.rutaGeneral=""+selectedFile; }
From source file:com.jug.MotherMachine.java
/** * Shows a JFileChooser set up to accept the selection of folders. * If 'cancel' is pressed this method terminates the MotherMachine app. * * @param guiFrame//ww w .jav a2s. c o m * parent frame * @param path * path to the folder to open initially * @return an instance of {@link File} pointing at the selected folder. */ private File showFolderChooser(final JFrame guiFrame, final String path) { final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(path)); chooser.setDialogTitle("Select folder containing image sequence..."); chooser.setFileFilter(new FileFilter() { @Override public final boolean accept(final File file) { return file.isDirectory(); } @Override public String getDescription() { return "We only take directories"; } }); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(guiFrame) == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } else { System.exit(0); return null; } }
From source file:com.cybercom.svp.machine.gui.MachineForm.java
private void buttomLoadFirmwareSettingFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttomLoadFirmwareSettingFileActionPerformed JFileChooser fileDialog = new JFileChooser(); fileDialog.setDialogTitle("Select firmware file"); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml"); fileDialog.setFileFilter(filter);//from w ww.j a v a 2 s .c o m fileDialog.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileDialog.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { try { String xml = FileUtils.readFileToString(fileDialog.getSelectedFile()); firmwareUpdateRequestSetting = xmlToObj(FirmwareUpdateRequest.class, xml); updateFirmwareSettings(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } }
From source file:com.openbravo.pos.imports.JPanelCSVImport.java
private void jbtnDbDriverLibActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnDbDriverLibActionPerformed resetFields();/*from w w w .j a v a2s . co m*/ // If CSV.last_file is null then use c:\ otherwise use saved dir JFileChooser chooser = new JFileChooser(last_folder == null ? "C:\\" : last_folder); FileNameExtensionFilter filter = new FileNameExtensionFilter("csv files", "csv"); chooser.setFileFilter(filter); chooser.showOpenDialog(null); File csvFile = chooser.getSelectedFile(); // check if a file was selected if (csvFile == null) { return; } File current_folder = chooser.getCurrentDirectory(); // If we have a file lets save the directory for later use if it's different from the old if (last_folder == null || !last_folder.equals(current_folder.getAbsolutePath())) { AppConfig CSVConfig = new AppConfig(config_file); CSVConfig.load(); CSVConfig.setProperty("CSV.last_folder", current_folder.getAbsolutePath()); last_folder = current_folder.getAbsolutePath(); try { CSVConfig.save(); } catch (IOException ex) { Logger.getLogger(JPanelCSVImport.class.getName()).log(Level.SEVERE, null, ex); } } String csv = csvFile.getName(); if (!(csv.trim().equals(""))) { csvFileName = csvFile.getAbsolutePath(); jFileName.setText(csvFileName); } }