List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:PreferencesTest.java
public PreferencesFrame() { // get position, size, title from preferences Preferences root = Preferences.userRoot(); final Preferences node = root.node("/com/horstmann/corejava"); int left = node.getInt("left", 0); int top = node.getInt("top", 0); int width = node.getInt("width", DEFAULT_WIDTH); int height = node.getInt("height", DEFAULT_HEIGHT); setBounds(left, top, width, height); // if no title given, ask user String title = node.get("title", ""); if (title.equals("")) title = JOptionPane.showInputDialog("Please supply a frame title:"); if (title == null) title = ""; setTitle(title);/*from ww w.j a v a 2 s.c o m*/ // set up file chooser that shows XML files final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); // accept all files ending with .xml chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory(); } public String getDescription() { return "XML files"; } }); // set up menus JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem exportItem = new JMenuItem("Export preferences"); menu.add(exportItem); exportItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (chooser.showSaveDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) { try { OutputStream out = new FileOutputStream(chooser.getSelectedFile()); node.exportSubtree(out); out.close(); } catch (Exception e) { e.printStackTrace(); } } } }); JMenuItem importItem = new JMenuItem("Import preferences"); menu.add(importItem); importItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (chooser.showOpenDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) { try { InputStream in = new FileInputStream(chooser.getSelectedFile()); Preferences.importPreferences(in); in.close(); } catch (Exception e) { e.printStackTrace(); } } } }); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { node.putInt("left", getX()); node.putInt("top", getY()); node.putInt("width", getWidth()); node.putInt("height", getHeight()); node.put("title", getTitle()); System.exit(0); } }); }
From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java
private void saveBackupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBackupButtonActionPerformed DatabaseInfo info = (DatabaseInfo) competitionList.getSelectedValue(); if (info == null || !info.local) return;// www. j ava2 s. c o m JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("Event Manager Files", "evm")); if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); if (!file.getName().toLowerCase().endsWith(".evm")) file = new File(file.getAbsolutePath() + ".evm"); if (file.exists()) { int result = JOptionPane.showConfirmDialog(rootPane, file.getName() + " already exists. Overwrite file?", "Save Backup", JOptionPane.YES_NO_OPTION); if (result != JOptionPane.YES_OPTION) return; } try { File tempDir = Files.createTempDirectory("event-manager").toFile(); FileUtils.copyDirectory(info.localDirectory, tempDir); File lockFile = new File(tempDir, "update.dat.lock"); lockFile.delete(); /* change id */ Properties props = new Properties(); FileReader fr = new FileReader(new File(tempDir, "info.dat")); props.load(fr); fr.close(); props.setProperty("old-UUID", props.getProperty("UUID", "none")); props.setProperty("UUID", UUID.randomUUID().toString()); FileWriter fw = new FileWriter(new File(tempDir, "info.dat")); props.store(fw, ""); fw.close(); ZipUtils.zipFolder(tempDir, file, false); } catch (Exception e) { GUIUtils.displayError(this, "Failed to save file: " + e.getMessage()); } } }
From source file:gui.InboxPanel.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try {/*from ww w .j a va2 s .c o m*/ String name = GmailAPI.getAttachmentFilename(curId); System.out.println(name); if (name == "None") { JOptionPane.showMessageDialog(this, "No file attached on this email"); } else { JFileChooser chooser = new JFileChooser(); File defFile = new File(name); chooser.setSelectedFile(defFile); int filesave = chooser.showSaveDialog(null); if (filesave == JFileChooser.APPROVE_OPTION) { //chooser.getSelectedFile().se File file = chooser.getCurrentDirectory(); GmailAPI.getAttachments(GmailAPI.service, GmailAPI.USER, curId, file.getAbsolutePath(), chooser.getSelectedFile().getName()); } } } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:my.swingconnect.SwingConnectUI.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed //To BROWSE A FILE FROM THE DIRECTORY JFileChooser chooser = new JFileChooser(); //To enable showing hidden file chooser.setFileHidingEnabled(false); //To Enable selecting directory or files chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //To enable multiple file selections chooser.setMultiSelectionEnabled(true); //Choice of user to save or open a file chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setDialogTitle("Choose a file..."); //To user to select a file if (chooser.showOpenDialog(SwingConnectUI.this) == JFileChooser.APPROVE_OPTION) { targetFile = chooser.getSelectedFile(); String directory = targetFile.getPath(); jTextField4.setText(targetFile.toString()); // files = new File("/Users/pradil90/Desktop/207dropbox").listFiles(); files = new File(directory).listFiles(); for (File file : files) { if (file.isFile()) { results.add(file.getAbsolutePath()); // results.add(file.getName()); System.out.println(file); count++;//from w ww . j a v a 2 s . c om System.out.println(count); } } results.remove(0); jButton3.setEnabled(true); } }
From source file:de.quadrillenschule.azocamsyncd.gui.ConfigurationWizardJFrame.java
private void autoruninstalljButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoruninstalljButton1ActionPerformed boolean success = false; JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setApproveButtonText("Prepare card..."); File startFile = new File(System.getProperty("user.dir")); //Get the current directory // Find System Root while (!FileSystemView.getFileSystemView().isFileSystemRoot(startFile)) { startFile = startFile.getParentFile(); }// w ww. ja va 2s .c om jfc.setCurrentDirectory(startFile); int origDriveChooserRetVal = jfc.showDialog(rootPane, "Open"); if (origDriveChooserRetVal == JFileChooser.APPROVE_OPTION) { try { File myfile = new File(jfc.getSelectedFile().getAbsolutePath(), "autorun.sh"); myfile.createNewFile(); FileOutputStream fos; try { fos = new FileOutputStream(myfile); IOUtils.copy(getClass().getResourceAsStream( "/de/quadrillenschule/azocamsyncd/ftpservice/res/autorun.sh"), fos); fos.close(); success = true; } catch (FileNotFoundException ex) { Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex); } } if (!success) { JOptionPane.showMessageDialog(rootPane, "The WiFi is SD card could not be written to. Please check if you selected the right card and it is not write-protected.", "SD card could not be prepared", JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(rootPane, "The WiFi SD card is prepared for operating an FTP and Telnet server.", "Success!", JOptionPane.INFORMATION_MESSAGE); step0jCheckBox.setSelected(true); step0jCheckBox.setText("Done"); updateSelectedPanel(1); } }
From source file:io.gameover.utilities.pixeleditor.Pixelizer.java
private void saveImage(String description, String extension, Encoder encoder) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new FileNameExtensionFilter(description, extension)); if (fileChooser.showDialog(this, "Save") == JFileChooser.APPROVE_OPTION) { File f = fileChooser.getSelectedFile(); try {/*from w w w .j a va 2 s.c om*/ encoder.saveImage(f, frames); JOptionPane.showMessageDialog(this, "File " + f.getName() + " saved!"); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Failed to save " + f.getName() + ": " + e.getMessage(), "Error occured", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }
From source file:de.fionera.javamailer.gui.mainView.controllerMain.java
/** * Adds the Actionlisteners to the Mainview * * @param viewMain The Mainview//from w w w.j av a 2 s . c om */ private void addActionListener(viewMain viewMain) { /** * Changes the Amount in the AmountLabel when the slider is moved */ viewMain.getSetMailSettingsPanel().getSliderAmountMails().addChangeListener(e -> { Main.amountMails = ((JSlider) e.getSource()).getValue(); viewMain.getSetMailSettingsPanel().getLabelNumberAmountMails() .setText("" + ((JSlider) e.getSource()).getValue()); }); /** * Changes the Delay in the DelayLabel when the slider is moved */ viewMain.getSetMailSettingsPanel().getSliderDelayMails().addChangeListener(e -> { Main.delayMails = ((JSlider) e.getSource()).getValue(); viewMain.getSetMailSettingsPanel().getLabelNumberDelayMails() .setText("" + ((JSlider) e.getSource()).getValue()); }); /** * Closes the Program, when close is clicked */ viewMain.getCloseItem().addActionListener(e -> System.exit(0)); /** * Opens the Settings when the settingsbutton is clicked */ viewMain.getSettingsItem().addActionListener(e -> new controllerSettings()); /** * Save current Setup */ viewMain.getSaveSettings().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); JFrame parentFrame = new JFrame(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub"); jChooser.setFileFilter(filter); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.setDialogTitle("Select Setup"); int userSelection = jChooser.showSaveDialog(parentFrame); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = new File(jChooser.getSelectedFile() + ".jms"); saveSetup(viewMain, fileToSave, new ObjectMapper()); } }); /** * Load Setup */ viewMain.getLoadSettings().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub"); jChooser.setFileFilter(filter); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.setDialogTitle("Select Setup"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { if (file.getName().endsWith("jms")) { try { loadSetup(viewMain, file, new ObjectMapper()); } catch (Exception error) { error.printStackTrace(); } } } }); /** * Opens the Open File dialog and start the Parsing of it */ viewMain.getSelectRecipientsPanel().getSelectExcelFileButton().addActionListener(e -> { DefaultTableModel model; JFileChooser jChooser = new JFileChooser(); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel 97 - 2003 (.xls)", "xls")); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel (.xlsx)", "xlsx")); jChooser.setDialogTitle("Select only Excel workbooks"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { parseFilesForImport parseFilesForImport = new parseFilesForImport(); if (file.getName().endsWith("xls")) { ArrayList returnedData = parseFilesForImport.parseXLSFile(file); model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1)); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable() .setPreferredSize(new Dimension(tableWidth, tableHeight)); } else if (file.getName().endsWith("xlsx")) { ArrayList returnedData = parseFilesForImport.parseXLSXFile(file); model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1)); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable() .setPreferredSize(new Dimension(tableWidth, tableHeight)); } else { JOptionPane.showMessageDialog(null, "Please select only Excel file.", "Error", JOptionPane.ERROR_MESSAGE); model = new DefaultTableModel(); } } else { model = new DefaultTableModel(); } viewMain.getSelectRecipientsPanel().getTable().setModel(model); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable().setPreferredSize(new Dimension(tableWidth, tableHeight)); viewMain.getCheckAllSettings().getLabelRecipientsAmount().setText("" + model.getRowCount()); viewMain.getCheckAllSettings().getLabelTimeAmount() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue() * viewMain.getSelectRecipientsPanel().getTable().getRowCount() / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue() + " Seconds"); }); /** * Starts the sending of th Mails, when the send button is clicked */ viewMain.getCheckAllSettings().getSendMails().addActionListener(e -> { String subject = viewMain.getSetMailSettingsPanel().getFieldSubject().getText(); Sender sender = (Sender) viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem(); JTable table = viewMain.getSelectRecipientsPanel().getTable(); if (table != null && sender != null && !subject.equals("")) { new sendMails(viewMain); } }); /** * Clears the Table on buttonclick */ viewMain.getSelectRecipientsPanel().getClearTableButton().addActionListener(e -> { viewMain.getSelectRecipientsPanel().getTable().setModel(new DefaultTableModel()); viewMain.getSelectRecipientsPanel().getTable().setBackground(null); }); /** * Removes a single Row on menu click in the editMailPanel */ viewMain.getSelectRecipientsPanel().getDeleteRow().addActionListener(e -> { ((DefaultTableModel) viewMain.getSelectRecipientsPanel().getTable().getModel()) .removeRow(viewMain.getSelectRecipientsPanel().getTable().getSelectedRowCount()); viewMain.getSelectRecipientsPanel().getTable().setBackground(null); }); /** * The Changes the displayed Value when the Time in the Timespinner is getting changed. */ viewMain.getSetMailSettingsPanel().getTimeSpinner().addChangeListener(e -> { parseDate.parseDate(viewMain); viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, " + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining"); viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString()); viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate()); }); viewMain.getSetMailSettingsPanel().getDatePicker().addActionListener(e -> { parseDate.parseDate(viewMain); viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, " + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining"); viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString()); viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate()); }); /** * Actionevent for the Edit Sender Button */ viewMain.getSetMailSettingsPanel().getButtonEditSender() .addActionListener(e -> new controllerEditSender(controllerMain)); /** * Actionevent for the Import Button in the EditMail View */ viewMain.getEditMailPanel().getImportWord().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Word 97 - 2003 (.doc)", "doc")); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("HTML File (.html)", "html")); jChooser.setDialogTitle("Select only Word Documents"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { parseFilesForImport parseFilesForImport = new parseFilesForImport(); if (file.getName().endsWith("doc")) { String returnedData = parseFilesForImport.parseDOCFile(file); viewMain.getEditMailPanel().setEditorText(returnedData); } else if (file.getName().endsWith("html")) { String content = ""; try { content = Jsoup.parse(file, "UTF-8").toString(); } catch (IOException e1) { e1.printStackTrace(); } viewMain.getEditMailPanel().setEditorText(content); } else { JOptionPane.showMessageDialog(null, "Please select a Document file.", "Error", JOptionPane.ERROR_MESSAGE); } } }); /** * The Tab Changelistener * The first if Statement sets the Labels on the Checkallsettings Panel to the right Values */ viewMain.getTabbedPane().addChangeListener(e -> { if (viewMain.getTabbedPane().getSelectedComponent() == viewMain.getCheckAllSettings()) { viewMain.getCheckAllSettings().getLabelMailBelow() .setText(viewMain.getEditMailPanel().getEditorText()); //Displays the Mail viewMain.getCheckAllSettings().getLabelRecipientsAmount() .setText("" + viewMain.getSelectRecipientsPanel().getTable().getModel().getRowCount()); //Displays the Amount of Recipients if (viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem() != null) { viewMain.getCheckAllSettings().getLabelFromInserted().setText( viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem().toString()); } else { viewMain.getCheckAllSettings().getLabelFromInserted().setText("Select a Sender first"); } viewMain.getCheckAllSettings().getLabelSubjectInserted() .setText(viewMain.getSetMailSettingsPanel().getFieldSubject().getText()); //Displays the Subject if (viewMain.getSetMailSettingsPanel().getCheckBoxDelayMails().isSelected()) { viewMain.getCheckAllSettings().getLabelDelay().setVisible(true); viewMain.getCheckAllSettings().getLabelAmount().setVisible(true); viewMain.getCheckAllSettings().getLabelTime().setVisible(true); viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(true); viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(true); viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(true); viewMain.getCheckAllSettings().getLabelDelayNumber() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()); //The Delay Number viewMain.getCheckAllSettings().getLabelAmountNumber() .setText("" + viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()); //The Amount of Mail in one package viewMain.getCheckAllSettings().getLabelTimeAmount() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue() * viewMain.getSelectRecipientsPanel().getTable().getRowCount() / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue() + " Seconds"); //The Time the Sending needs } else { viewMain.getCheckAllSettings().getLabelDelay().setVisible(false); viewMain.getCheckAllSettings().getLabelAmount().setVisible(false); viewMain.getCheckAllSettings().getLabelTime().setVisible(false); viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(false); viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(false); viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(false); } if (viewMain.getSetMailSettingsPanel().getCheckBoxSendLater().isSelected()) { viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(true); viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(true); viewMain.getCheckAllSettings().getLabelSendingAt() .setText(viewMain.getSetMailSettingsPanel().getDate().toString()); } else { viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(false); viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(false); } } }); }
From source file:dylemator.UserResultList.java
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed if (this.filenameCombo.getSelectedIndex() == 0) return;/* w w w .ja v a 2s .c om*/ String sheetName = (String) this.filenameCombo.getSelectedItem(); Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet(sheetName); Row headerRow = sheet.createRow(0); String[] headers = exportData.get(0); int numOfColumns = headers.length; for (int i = 0, j = 0; i < numOfColumns; i++) { if (i == 1 || i == 2 || i == 3) // opuszcz. date, imie, nazwisko continue; Cell cell = headerRow.createCell(j++); cell.setCellValue(headers[i]); } int rowCount = exportData.size(); for (int rownum = 1; rownum < rowCount; rownum++) { Row row = sheet.createRow(rownum); String[] values = exportData.get(rownum); for (int i = 0, j = 0; i < numOfColumns; i++) { if (i == 1 || i == 2 || i == 3) // opuszcz. date, imie, nazwisko continue; Cell cell = row.createCell(j++); cell.setCellValue(values[i]); } } String defaultFilename = "Export.xlsx"; JFileChooser f = new JFileChooser(System.getProperty("user.dir")); f.setSelectedFile(new File(defaultFilename)); f.setDialogTitle("Wybierz nazw dla pliku eksportu"); f.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter ff = new FileFilter() { @Override public boolean accept(File file) { if (file.getName().endsWith(".xlsx")) return true; return false; } @Override public String getDescription() { return ""; } }; f.setFileFilter(ff); File file = null; int save = f.showSaveDialog(this); if (save == JFileChooser.APPROVE_OPTION) file = f.getSelectedFile(); else return; FileOutputStream out; try { out = new FileOutputStream(file); wb.write(out); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(UserResultList.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(UserResultList.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:gov.nij.er.ui.EntityResolutionDemo.java
private void handleLoadExcelDataCommand() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { @Override// w w w . j av a 2 s . c om public boolean accept(File f) { String name = f.getName(); return f.isDirectory() || name.endsWith(".xls") || name.endsWith(".xlsx"); } @Override public String getDescription() { return "Excel Workbooks (*.xls, *.xlsx)"; } }); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File file = fc.getSelectedFile(); try { new UIBlockingTask(new RunnableTask() { public void run() throws Exception { loadExcelData(file); } }).execute(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:jatoo.app.App.java
private File select(final File currentDirectory, final int fileSelectionMode) { JFileChooser fileChooser = new JFileChooser(currentDirectory); fileChooser.setFileSelectionMode(fileSelectionMode); int returnValue = fileChooser.showOpenDialog(window); if (returnValue == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFile(); }/* ww w. j ava 2s. c om*/ return null; }