List of usage examples for javax.swing JFileChooser OPEN_DIALOG
int OPEN_DIALOG
To view the source code for javax.swing JFileChooser OPEN_DIALOG.
Click Source Link
JFileChooser
supports an "Open" file operation. From source file:com.hexidec.ekit.EkitCore.java
/** * Method for reading in a serialized document from a file *///from w w w . ja v a2 s . co m public void serializeIn() throws IOException, ClassNotFoundException { File whatFile = getFileFromChooser(".", JFileChooser.OPEN_DIALOG, extsSer, Translatrix.getTranslationString("FiletypeSer")); if (whatFile != null) { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(whatFile)); htmlDoc = (ExtendedHTMLDocument) (ois.readObject()); ois.close(); registerDocument(htmlDoc); validate(); } refreshOnUpdate(); }
From source file:com.hexidec.ekit.EkitCore.java
/** * Method for obtaining a File for input/output using a JFileChooser dialog *///from w w w. j a v a2 s.co m private File getFileFromChooser(String startDir, int dialogType, String[] exts, String desc) { JFileChooser jfileDialog = new JFileChooser(startDir); jfileDialog.setDialogType(dialogType); jfileDialog.setFileFilter(new MutableFilter(exts, desc)); int optionSelected = JFileChooser.CANCEL_OPTION; if (dialogType == JFileChooser.OPEN_DIALOG) { optionSelected = jfileDialog.showOpenDialog(this); } else if (dialogType == JFileChooser.SAVE_DIALOG) { optionSelected = jfileDialog.showSaveDialog(this); } else // default to an OPEN_DIALOG { optionSelected = jfileDialog.showOpenDialog(this); } if (optionSelected == JFileChooser.APPROVE_OPTION) { return jfileDialog.getSelectedFile(); } return (File) null; }
From source file:v800_trainer.JCicloTronic.java
private void jMenuOpenallActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOpenallActionPerformed // Add your handling code here: int i;/*w ww.j a v a2 s . c om*/ StringBuffer Buffer = new StringBuffer(); String[] liste = new String[1]; byte Data[] = new byte[81930]; File path = new File(Properties.getProperty("data.dir")); File Datei; FileFilter directoryFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } public String getDescription() { return ""; }; }; chooser.setCurrentDirectory( new java.io.File(Properties.getProperty("import.dir", Properties.getProperty("data.dir")))); chooser.setDialogType(JFileChooser.OPEN_DIALOG); ExampleFileFilter filtera = new ExampleFileFilter(); ExampleFileFilter filterb = new ExampleFileFilter(); ExampleFileFilter filterc = new ExampleFileFilter(); ExampleFileFilter filterd = new ExampleFileFilter(); ExampleFileFilter filtere = new ExampleFileFilter(); filtera.addExtension("dat"); filtera.setDescription("HAC Rohdaten"); filterb.addExtension("tur"); filterb.setDescription("Hactronic Dateien"); filterc.addExtension("hrm"); filterc.setDescription("Polar Daten"); filterd.addExtension(""); filterd.setDescription("Polar V800 Verzeichnis"); filtere.addExtension("csv"); filtere.setDescription("Polar V800 CSV Flow export"); chooser.resetChoosableFileFilters(); chooser.addChoosableFileFilter(filtera); chooser.addChoosableFileFilter(filterb); chooser.addChoosableFileFilter(filterc); chooser.addChoosableFileFilter(filterd); chooser.addChoosableFileFilter(filtere); chooser.setFileFilter(filtere); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showDialog(this, null); if (returnVal == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile().getName().endsWith(".dat")) { path = new File(chooser.getCurrentDirectory().getPath()); } else { path = new File(chooser.getSelectedFile().getPath()); } if (chooser.getFileFilter().equals(filtera)) { liste = path.list(new DirFilter(".dat")); } if (chooser.getFileFilter().equals(filterb)) { liste = path.list(new DirFilter(".tur")); } if (chooser.getFileFilter().equals(filterc)) { liste = path.list(new DirFilter(".hrm")); } if (chooser.getFileFilter().equals(filtere)) { liste = path.list(new DirFilter(".csv")); } if (chooser.getFileFilter().equals(filterd)) { File[] files = path.listFiles(); ArrayList<String> pathliste = new ArrayList(); for (File file : files) { try { if (file.isDirectory()) { pathliste.add(file.getCanonicalPath()); } } catch (Exception e) { } } Thread thread = new Thread(new Runnable() { public void run() { setCursor(new Cursor(Cursor.WAIT_CURSOR)); pm = new ProgressMonitor(JCicloTronic.this, "Importiere...", "", 0, 100); pm.setMillisToPopup(1); v800export V800_export = new v800export(); V800_export.export_sessions(JCicloTronic.this, pathliste); pm.close(); ChangeModel(); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); try { Thread.sleep(100); } catch (Exception e) { if (Thread.interrupted()) { return; } } } }); thread.start(); return; } //alle auer V800 Dateien importieren if (liste == null) { JOptionPane.showMessageDialog(null, "Keine Rohdaten-Files gefunden!", "Achtung!", JOptionPane.ERROR_MESSAGE); return; } final String[] liste_final = liste.clone(); final File path_final = path; Thread thread = new Thread(new Runnable() { public void run() { File Datei; byte Data[] = new byte[81930]; setCursor(new Cursor(Cursor.WAIT_CURSOR)); pm = new ProgressMonitor(JCicloTronic.this, "Importiere...", "", 0, 100); pm.setMillisToPopup(1); for (int i = 0; i < liste_final.length; i++) { pm.setProgress((int) 100.0 * i / liste_final.length); pm.setNote(liste_final[i]); try { Eingabedatei = new java.io.FileInputStream(path_final.getPath() + SystemProperties.getProperty("file.separator") + liste_final[i]); try { Datei = new File(path_final.getPath() + SystemProperties.getProperty("file.separator") + liste_final[i]); Data = new byte[(int) Datei.length()]; // Eingabedatei.read() Eingabedatei.read(Data); Eingabedatei.close(); if (chooser.getFileFilter().equals(filtera)) { ExtractTour(Data); } if (chooser.getFileFilter().equals(filterb)) { ExtractHactronicFile(Data); } if (chooser.getFileFilter().equals(filterc)) { ExtractPolarFile(Data); } if (chooser.getFileFilter().equals(filtere)) { ExtractCSV(Data); } } catch (IOException e) { JOptionPane.showMessageDialog(null, "IO-Fehler bei Datenlesen", "Achtung!", JOptionPane.ERROR_MESSAGE); } } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(null, "IO-Fehler bei " + path_final.getPath() + SystemProperties.getProperty("file.separator") + liste_final[i], "Achtung!", JOptionPane.ERROR_MESSAGE); } } pm.close(); JOptionPane.showMessageDialog(null, "Daten Ende", "Achtung!", JOptionPane.ERROR_MESSAGE); Properties.setProperty("import.dir", chooser.getCurrentDirectory().getPath()); ChangeModel(); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); try { Thread.sleep(100); } catch (Exception e) { if (Thread.interrupted()) { return; } } } }); thread.start(); } }
From source file:v800_trainer.JCicloTronic.java
private void jMenuOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOpenActionPerformed // Add your handling code here: byte Data[] = new byte[81930]; File Datei;//from w w w. j a v a 2s. com int i, j; chooser.setCurrentDirectory( new java.io.File(Properties.getProperty("import.dir", Properties.getProperty("data.dir")))); chooser.setDialogType(JFileChooser.OPEN_DIALOG); ExampleFileFilter filtera = new ExampleFileFilter(); ExampleFileFilter filterb = new ExampleFileFilter(); ExampleFileFilter filterc = new ExampleFileFilter(); ExampleFileFilter filterd = new ExampleFileFilter(); ExampleFileFilter filtere = new ExampleFileFilter(); // ExampleFileFilter filterc = new ExampleFileFilter(); filtera.addExtension("dat"); filtera.setDescription("HAC Rohdaten"); filterb.addExtension("tur"); filterb.setDescription("Hactronic Dateien"); filterc.addExtension("hrm"); filterc.setDescription("Polar Daten"); filterd.addExtension(""); filterd.setDescription("Polar V800 Verzeichnis"); filtere.addExtension("csv"); filtere.setDescription("Polar V800 CSV Flow export"); chooser.resetChoosableFileFilters(); chooser.addChoosableFileFilter(filtera); chooser.addChoosableFileFilter(filterb); chooser.addChoosableFileFilter(filterc); chooser.addChoosableFileFilter(filterd); chooser.addChoosableFileFilter(filtere); chooser.setFileFilter(filtere); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int returnVal = chooser.showDialog(this, null); if (returnVal == JFileChooser.APPROVE_OPTION) { try { if (chooser.getFileFilter().equals(filterd)) { if (chooser.getSelectedFile().isDirectory() == true) { ArrayList<String> files = new ArrayList(); files.add(chooser.getSelectedFile().getPath()); v800export V800_export = new v800export(); V800_export.export_sessions(this, files); } else { return; } } else { Datei = new File(chooser.getSelectedFile().toString()); Data = new byte[(int) Datei.length()]; Eingabedatei = new java.io.FileInputStream(chooser.getSelectedFile()); Eingabedatei.read(Data); Eingabedatei.close(); if (chooser.getFileFilter().equals(filtera)) { ExtractTour(Data); } if (chooser.getFileFilter().equals(filterb)) { ExtractHactronicFile(Data); } if (chooser.getFileFilter().equals(filterc)) { ExtractPolarFile(Data); } if (chooser.getFileFilter().equals(filtere)) { ExtractCSV(Data); } } } catch (IOException e) { JOptionPane.showMessageDialog(null, "IO-Fehler bei Datenlesen", "Achtung!", JOptionPane.ERROR_MESSAGE); } } else { return; } Properties.setProperty("import.dir", chooser.getCurrentDirectory().getPath()); JOptionPane.showMessageDialog(null, "Daten Ende", "Achtung!", JOptionPane.ERROR_MESSAGE); ChangeModel(); }
From source file:v800_trainer.JCicloTronic.java
private void Info_Button_Suche_TrackLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Info_Button_Suche_TrackLogActionPerformed ExampleFileFilter filtera = new ExampleFileFilter(); filtera.addExtension("kmz"); filtera.addExtension("TCX"); filtera.addExtension("GPX"); filtera.setDescription("Track Datei"); chooser.resetChoosableFileFilters(); chooser.addChoosableFileFilter(filtera); chooser.setFileFilter(filtera);//from ww w. j a va2s. c om if (new java.io.File(Info_Track_Log.getText()).exists()) { chooser.setCurrentDirectory(new java.io.File(Info_Track_Log.getText())); } else { chooser.setCurrentDirectory(new java.io.File(Properties.getProperty("GPS.dir"))); } chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = chooser.showDialog(this, null); if (returnVal == JFileChooser.APPROVE_OPTION) { Info_Track_Log.setText(chooser.getSelectedFile().getPath()); } }
From source file:app.RunApp.java
/** * Load multiple datasets//from w w w .ja v a 2 s . co m * * @param returnVal Value returned from openDialog * @param chooser Chooser * @return Positive number if successfull and negative otherwise */ private int loadMultiDataset(int returnVal, JFileChooser chooser) { if (returnVal == JFileChooser.OPEN_DIALOG) { File[] files = chooser.getSelectedFiles(); for (File f1 : files) { String datasetName = f1.getName(); datasetName = datasetName.substring(0, datasetName.length() - 5); if (datasetNames.contains(datasetName)) { JOptionPane.showMessageDialog(null, "The dataset is duplicated.", "alert", JOptionPane.ERROR_MESSAGE); return -1; } String arffFilename = f1.getAbsolutePath(); xmlFilename = DataIOUtils.getXMLString(arffFilename); xmlFilename = DataIOUtils.getFilePath(xmlFilename); boolean isMeka = false; String xmlPath = arffFilename.substring(0, arffFilename.length() - 5) + ".xml"; FileReader fr; try { fr = new FileReader(arffFilename); BufferedReader bf = new BufferedReader(fr); String sString = bf.readLine(); int labelFound = 0; String labelName; String[] labelNamesFound; isMeka = DataIOUtils.isMeka(sString); areMeka.add(isMeka); if (isMeka) { isMeka = true; int labelCount = DataIOUtils.getLabelsFromARFF(sString); if (labelCount > 0) { labelNamesFound = new String[labelCount]; while (labelFound < labelCount) { sString = bf.readLine(); labelName = DataIOUtils.getLabelNameFromLine(sString); if (labelName != null) { labelNamesFound[labelFound] = labelName; labelFound++; } } } else { labelCount = Math.abs(labelCount); labelNamesFound = new String[labelCount]; String[] sStrings = new String[labelCount]; while (!(sString = bf.readLine()).contains("@data")) { if (!sString.trim().equals("")) { for (int s = 0; s < labelCount - 1; s++) { sStrings[s] = sStrings[s + 1]; } sStrings[labelCount - 1] = sString; } } for (int i = 0; i < labelCount; i++) { labelName = DataIOUtils.getLabelNameFromLine(sStrings[i]); if (labelName != null) { labelNamesFound[labelFound] = labelName; labelFound++; } } } BufferedWriter bwXml = new BufferedWriter(new FileWriter(xmlPath)); PrintWriter wrXml = new PrintWriter(bwXml); DataIOUtils.writeXMLFile(wrXml, labelNamesFound); bwXml.close(); wrXml.close(); xmlFilename = DataIOUtils.getFilePath(xmlPath); } else { isMeka = false; } } catch (FileNotFoundException ex) { Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); } try { MultiLabelInstances current = new MultiLabelInstances(arffFilename, xmlFilename); if (isMeka) { File f2 = new File(xmlFilename); f2.delete(); } listDatasets.add(current); datasetNames.add(datasetName); list.addElement(datasetName); } catch (InvalidDataFormatException ex) { Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); } } } return 1; }
From source file:app.RunApp.java
/** * Load dataset in principal tab//w w w . j ava2s . c o m * * @param returnVal Positive number if successfull and negative otherwise * @param fileChooser Chooser * @param deleteXML Boolean indicating if the generated xml must be removed * @return */ private int loadDataset(int returnVal, JFileChooser fileChooser, boolean deleteXML) { if (returnVal == JFileChooser.OPEN_DIALOG) { File f1 = fileChooser.getSelectedFile(); datasetName = f1.getName(); datasetCurrentName = datasetName.substring(0, datasetName.length() - 5); String arffFilename = f1.getAbsolutePath(); xmlPath = arffFilename.substring(0, arffFilename.length() - 5) + ".xml"; xmlFilename = DataIOUtils.getFileName(xmlPath); File fileTmp = new File(xmlPath); FileReader fr; try { views.clear(); ((DefaultTableModel) jTable2.getModel()).getDataVector().removeAllElements(); ((DefaultTableModel) jTable3.getModel()).getDataVector().removeAllElements(); fr = new FileReader(arffFilename); BufferedReader bf = new BufferedReader(fr); String sString = bf.readLine(); if (sString.contains("-V:")) { mv = true; TabPrincipal.setEnabledAt(7, true); String s2 = sString.split("'")[1]; s2 = s2.split("-V:")[1]; String[] intervals = s2.split("!"); Vector<Vector<Integer>> newIntervals = new Vector<>(); int[] intervalsSize = new int[intervals.length]; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; double mean = 0; for (int i = 0; i < intervals.length; i++) { newIntervals.add(new Vector<Integer>()); String[] aux2; viewsIntervals.put("View " + (i + 1), intervals[i]); if (intervals[i].contains(",")) { aux2 = intervals[i].split(","); for (int j = 0; j < aux2.length; j++) { if (aux2[j].contains("-")) { int a = Integer.parseInt(aux2[j].split("-")[0]); int b = Integer.parseInt(aux2[j].split("-")[1]); for (int k = a; k <= b; k++) { newIntervals.get(i).add(k); } } else { newIntervals.get(i).add(Integer.parseInt(aux2[j])); } } } else { if (intervals[i].contains("-")) { int a = Integer.parseInt(intervals[i].split("-")[0]); int b = Integer.parseInt(intervals[i].split("-")[1]); for (int k = a; k <= b; k++) { newIntervals.get(i).add(k); } } else { newIntervals.get(i).add(Integer.parseInt(intervals[i])); } } } for (int i = 0; i < newIntervals.size(); i++) { Integer[] indices = new Integer[newIntervals.get(i).size()]; for (int j = 0; j < newIntervals.get(i).size(); j++) { indices[j] = newIntervals.get(i).get(j); } System.out.println(Arrays.toString(indices)); views.put("View " + (i + 1), indices); if (newIntervals.get(i).size() > max) { max = newIntervals.get(i).size(); } if (newIntervals.get(i).size() < min) { min = newIntervals.get(i).size(); } mean += newIntervals.get(i).size(); } mean /= intervalsSize.length; labelNumViewsValue.setText(Integer.toString(intervalsSize.length)); labelMaxNumAttrViewValue.setText(Integer.toString(max)); labelMinNumAttrViewValue.setText(Integer.toString(min)); labelMeanNumAttrViewValue.setText(Double.toString(mean)); } else { TabPrincipal.setEnabledAt(7, false); mv = false; } int labelFound = 0; String labelName; String[] labelNamesFound; if (DataIOUtils.isMeka(sString)) { deleteXML = true; isMeka = true; int labelCount = DataIOUtils.getLabelsFromARFF(sString); if (labelCount > 0) { labelNamesFound = new String[labelCount]; while (labelFound < labelCount) { sString = bf.readLine(); labelName = DataIOUtils.getLabelNameFromLine(sString); if (labelName != null) { labelNamesFound[labelFound] = labelName; labelFound++; } } } else { labelCount = Math.abs(labelCount); labelNamesFound = new String[labelCount]; String[] sStrings = new String[labelCount]; while (!(sString = bf.readLine()).contains("@data")) { if (!sString.trim().equals("")) { for (int s = 0; s < labelCount - 1; s++) { sStrings[s] = sStrings[s + 1]; } sStrings[labelCount - 1] = sString; } } for (int i = 0; i < labelCount; i++) { labelName = DataIOUtils.getLabelNameFromLine(sStrings[i]); if (labelName != null) { labelNamesFound[labelFound] = labelName; labelFound++; } } } BufferedWriter bwXml = new BufferedWriter(new FileWriter(xmlPath)); PrintWriter wrXml = new PrintWriter(bwXml); DataIOUtils.writeXMLFile(wrXml, labelNamesFound); bwXml.close(); wrXml.close(); xmlFilename = DataIOUtils.getFilePath(xmlPath); fileTmp = new File(xmlPath); } else { isMeka = false; } } catch (FileNotFoundException ex) { Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); return -1; } catch (IOException ex) { Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); return -1; } if (!fileTmp.exists()) { xmlPath = DataIOUtils.getXMLString(arffFilename); xmlFilename = DataIOUtils.getFilePath(xmlPath); } //Enable tabs TabPrincipal.setEnabledAt(1, true); TabPrincipal.setEnabledAt(2, true); TabPrincipal.setEnabledAt(3, true); TabPrincipal.setEnabledAt(4, true); TabPrincipal.setEnabledAt(5, true); TabPrincipal.setEnabledAt(6, true); try { File f = new File(xmlFilename); if (f.exists() && !f.isDirectory()) { //MultiLabelInstances dataset_temp = new MultiLabelInstances(filename_database_arff, xmlFilename); } else { JOptionPane.showMessageDialog(null, "File could not be loaded.", "alert", JOptionPane.ERROR_MESSAGE); return -1; } } catch (Exception ex) { Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); progressBar.setVisible(false); progressFrame.setVisible(false); progressFrame.repaint(); return -1; } initTableMetrics(); clearTableMetricsPrincipal(); File f = new File(xmlFilename); if (f.exists() && !f.isDirectory()) { loadDataset(arffFilename, xmlFilename); } else { loadDataset(arffFilename, null); } if (deleteXML) { File f2 = new File(xmlFilename); f2.delete(); } textChooseFile.setText(arffFilename); } if (mv) { if (((DefaultTableModel) jTable2.getModel()).getRowCount() > 0) { ((DefaultTableModel) jTable2.getModel()).getDataVector().removeAllElements(); } for (int i = 0; i < views.size(); i++) { MultiLabelInstances view = dataset.clone(); try { Instances inst = view.getDataSet(); int[] attributes = Utils.toPrimitive(views.get("View " + (i + 1))); int[] toKeep = new int[attributes.length + dataset.getNumLabels()]; System.arraycopy(attributes, 0, toKeep, 0, attributes.length); int[] labelIndices = dataset.getLabelIndices(); System.arraycopy(labelIndices, 0, toKeep, attributes.length, dataset.getNumLabels()); Remove filterRemove = new Remove(); filterRemove.setAttributeIndicesArray(toKeep); filterRemove.setInvertSelection(true); filterRemove.setInputFormat(inst); MultiLabelInstances modifiedDataset = new MultiLabelInstances( Filter.useFilter(view.getDataSet(), filterRemove), dataset.getLabelsMetaData()); LxIxF lif = new LxIxF(); lif.calculate(modifiedDataset); RatioInstancesToAttributes ratioInstAtt = new RatioInstancesToAttributes(); ratioInstAtt.calculate(modifiedDataset); AvgGainRatio avgGainRatio = new AvgGainRatio(); avgGainRatio.calculate(modifiedDataset); ((DefaultTableModel) jTable2.getModel()).addRow( new Object[] { "View " + (i + 1), attributes.length, getMetricValueFormatted(lif), getMetricValueFormatted(ratioInstAtt), getMetricValueFormatted(avgGainRatio) }); } catch (Exception ex) { Logger.getLogger(RunApp.class.getName()).log(Level.SEVERE, null, ex); } } } return 1; }
From source file:no.java.swing.SingleSelectionFileDialog.java
private Result showJFileChooser(Component target, boolean open) { JFileChooser chooser = new JFileChooser(previousDirectory); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(filter);// w w w .j a v a 2 s . c om chooser.setAcceptAllFileFilterUsed(filter == null); chooser.setDialogType(open ? JFileChooser.OPEN_DIALOG : JFileChooser.SAVE_DIALOG); int selection = chooser.showDialog(target, null); switch (selection) { case JFileChooser.APPROVE_OPTION: this.selected = chooser.getSelectedFile(); if (rememberPreviousLocation) { previousDirectory = chooser.getCurrentDirectory(); } return Result.APPROVE; case JFileChooser.CANCEL_OPTION: case JFileChooser.ERROR_OPTION: default: this.selected = null; return Result.ERROR; } }
From source file:org.apache.cayenne.modeler.dialog.codegen.GeneratorController.java
/** * An action method that pops up a file chooser dialog to pick the * generation directory./* www . j a va2 s . co m*/ */ public void selectOutputFolderAction() { JTextField outputFolder = ((GeneratorControllerPanel) getView()).getOutputFolder(); String currentDir = outputFolder.getText(); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogType(JFileChooser.OPEN_DIALOG); // guess start directory if (!Util.isEmptyString(currentDir)) { chooser.setCurrentDirectory(new File(currentDir)); } else { FSPath lastDir = Application.getInstance().getFrameController().getLastDirectory(); lastDir.updateChooser(chooser); } int result = chooser.showOpenDialog(getView()); if (result == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); // update model String path = selected.getAbsolutePath(); outputFolder.setText(path); setOutputPath(path); } }
From source file:org.apache.cayenne.modeler.dialog.pref.ClasspathPreferences.java
protected void chooseClassEntry(FileFilter filter, String title, int selectionMode) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(selectionMode); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setAcceptAllFileFilterUsed(true); getLastDirectory().updateChooser(chooser); if (filter != null) { chooser.addChoosableFileFilter(filter); }/* w w w . j a v a2 s .c o m*/ chooser.setDialogTitle(title); File selected = null; int result = chooser.showOpenDialog(view); if (result == JFileChooser.APPROVE_OPTION) { selected = chooser.getSelectedFile(); } if (selected != null) { if (!classPathEntries.contains(selected.getAbsolutePath())) { // store last dir in preferences getLastDirectory().updateFromChooser(chooser); int len = classPathEntries.size(); int key = ++counter; String value = selected.getAbsolutePath(); addChangedPreferences(Integer.toString(key), value); classPathEntries.add(value); classPathKeys.add(Integer.toString(key)); tableModel.fireTableRowsInserted(len, len); } } }