List of usage examples for javax.swing JFileChooser DIRECTORIES_ONLY
int DIRECTORIES_ONLY
To view the source code for javax.swing JFileChooser DIRECTORIES_ONLY.
Click Source Link
From source file:com.moneydance.modules.features.importlist.io.DefaultDirectoryChooser.java
@Override void chooseBaseDirectory() { final JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(this.getLocalizable().getDirectoryChooserTitle()); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // disable the "All files" option. fileChooser.setAcceptAllFileFilterUsed(false); try {//from w w w . java2 s. c o m fileChooser.setCurrentDirectory(FileUtils.getUserDirectory()); } catch (SecurityException e) { LOG.log(Level.WARNING, e.getMessage(), e); } if (this.getBaseDirectory() != null) { final File parentDirectory = this.getBaseDirectory().getParentFile(); fileChooser.setCurrentDirectory(parentDirectory); } if (fileChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) { return; } this.getPrefs().setBaseDirectory(fileChooser.getSelectedFile().getAbsolutePath()); LOG.info(String.format("Base directory is %s", this.getPrefs().getBaseDirectory())); }
From source file:net.mitnet.tools.pdf.book.publisher.ui.gui.BaseBookPublisherGUI.java
protected void browseDir(JTextField dirField) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fileChooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); String selectedFilePath = selectedFile.getAbsolutePath(); dirField.setText(selectedFilePath); }//from w w w.ja v a 2 s .co m }
From source file:de.burrotinto.jKabel.dbauswahlAS.DBAuswahlAAS.java
private String choosePath(String pfad) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(pfad)); chooser.setDialogTitle("DB Pfad"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); return chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION ? null : chooser.getSelectedFile().getPath() + File.separator; }
From source file:org.pmedv.jake.commands.OpenPlayerViewCommand.java
@Override public void execute() { final ApplicationContext ctx = AppContext.getApplicationContext(); final ApplicationWindow win = (ApplicationWindow) ctx.getBean(BeanDirectory.WINDOW_APPLICATION); /**//from w w w . j ava 2s. c o m * Get last selected folder to simplify file browsing */ if (AppContext.getLastSelectedFolder() == null) AppContext.setLastSelectedFolder(System.getProperty("user.home")); JFileChooser fc = new JFileChooser(AppContext.getLastSelectedFolder()); fc.setDialogTitle("Open directory"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fc.showOpenDialog(win); if (result == JFileChooser.CANCEL_OPTION) return; AppContext.setLastSelectedFolder(fc.getSelectedFile().getAbsolutePath()); List<File> files = new ArrayList<File>(); FileUtils.findFile(files, fc.getSelectedFile(), ".mp3", true, true); final PlayerController controller = new PlayerController(files); JakeUtil.updateRecentFiles(fc.getSelectedFile().getAbsolutePath()); View view = new View(fc.getSelectedFile().getAbsolutePath(), null, controller.getPlayerView()); view.addListener(new DockingWindowAdapter() { @Override public void windowClosing(DockingWindow arg0) throws OperationAbortedException { if (controller.getPlayer() != null) controller.getPlayer().close(); controller.getPlayFileCommand().setPlaying(false); } }); openEditor(view); }
From source file:com.webcrawler.WebCrawlerMain.java
public void initInternalComponents() { progBarDownload.setStringPainted(true); fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setVisible(false);//from w w w . j a va 2 s . com }
From source file:com.ev.export.AnnualPDFExporter.java
@Override public String chooseFile() throws IOException { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.showSaveDialog(MainFrame.getInstance()); File selectedFile = jfc.getSelectedFile(); if (selectedFile == null) { throw new IOException("No file chosen."); }// www . jav a 2s . c o m return selectedFile.getCanonicalPath() + File.separator + year + PDF_SUFFIX; }
From source file:kuvalataaja.user_interface.GUI.java
/** * Select a directory and pass it to Main.run *///w w w . ja va 2 s. com public void runTheProgram() { String separatorString = openSettings(); char separator = separatorString.charAt(0); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.showDialog(this, "Please select your Music folder"); File f = new File(chooser.getSelectedFile().getPath()); textArea.setText("Working..."); String[] result = kuvalataaja.kuvalataaja.Main.run(f, separator); //Shows a list of which album covers were fetched showResult(result); }
From source file:com.swg.parse.docx.OpenFolderAction.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File("C:/")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (selectedFile != null) { fc.setSelectedFile(selectedFile); }/*from w w w . j a v a 2s .c om*/ int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data"); JFrame jf = new JFrame("Progress Bar"); Container Jcontent = jf.getContentPane(); JProgressBar progressBar = new JProgressBar(); progressBar.setValue(0); progressBar.setStringPainted(true); Jcontent.add(progressBar, BorderLayout.NORTH); jf.setSize(300, 60); jf.setVisible(true); //we needed a new thread for a functional progress bar on the JFrame new Thread(new Runnable() { public void run() { if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); selectedFile = file; FileFilter fileFilter = new WildcardFileFilter("*.docx"); File[] files = selectedFile.listFiles(fileFilter); double cnt = 0, cnt2 = 0; //number of how many .docx is in the folder for (File f : files) { if (!f.getAbsolutePath().contains("~")) cnt2++; } for (File f : files) { cnt++; pathToTxtFile = f.getAbsolutePath().replace(".docx", ".txt"); TxtFile = new File(pathToTxtFile); //---------------------------------------------------- String zipFilePath = "C:\\Users\\fja2\\Desktop\\junk\\Test\\test.zip"; String destDirectory = "C:\\Users\\fja2\\Desktop\\junk\\Test " + cnt; UnzipUtility unzipper = new UnzipUtility(); try { File zip = new File(zipFilePath); File directory = new File(destDirectory); FileUtils.copyFile(f, zip); unzipper.UnzipUtility(zip, directory); zip.delete(); String mediaPath = destDirectory + "/word/media/"; File mediaDir = new File(mediaPath); for (File fil : mediaDir.listFiles()) { FileUtils.copyFile(fil, new File("C:\\Users\\PXT1\\Desktop\\test\\Pictures\\" + f.getName() + "\\" + fil.getName())); } FileUtils.deleteDirectory(directory); } catch (Exception ex) { ex.printStackTrace(); } //---------------------------------------------------- //if the txt file doesn't exist, it tries to convert whatever //can be the txt into the actual txt. if (!TxtFile.exists()) { pathToTxtFile = f.getAbsolutePath().replace(".docx", ""); TxtFile = new File(pathToTxtFile); pathToTxtFile += ".txt"; TxtFile.renameTo(new File(pathToTxtFile)); TxtFile = new File(pathToTxtFile); } String content = ""; String POIContent = ""; try { content = readTxtFile(); version = DetermineVersion(content); NewExtract ext = new NewExtract(); ext.extract(content, f.getAbsolutePath(), version, (int) cnt); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } double tempProg = (cnt / cnt2) * 100; progressBar.setValue((int) tempProg); System.gc(); } } else { //do nothing } } }).start(); System.gc(); }
From source file:AST.DesignPatternDetection.java
private void btPathFinderActionPerformed(ActionEvent e) { // TODO add your code here JFileChooser f = new JFileChooser(); f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); f.showDialog(null, null);//from w w w .ja v a 2 s.c o m tfPath.setText(f.getSelectedFile().toString()); vertices.clear(); dugumler.clear(); methods.clear(); //System.out.println(f.getCurrentDirectory()); //System.out.println(f.getSelectedFile()); }
From source file:SimpleFileChooser.java
public SimpleFileChooser() { super("File Chooser Test Frame"); setSize(350, 200);//from ww w . j a va2s . c om setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); JButton openButton = new JButton("Open"); JButton saveButton = new JButton("Save"); JButton dirButton = new JButton("Pick Dir"); final JLabel statusbar = new JLabel("Output of your selection will go here"); // Create a file chooser that opens up as an Open dialog openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); int option = chooser.showOpenDialog(SimpleFileChooser.this); if (option == JFileChooser.APPROVE_OPTION) { File[] sf = chooser.getSelectedFiles(); String filelist = "nothing"; if (sf.length > 0) filelist = sf[0].getName(); for (int i = 1; i < sf.length; i++) { filelist += ", " + sf[i].getName(); } statusbar.setText("You chose " + filelist); } else { statusbar.setText("You canceled."); } } }); // Create a file chooser that opens up as a Save dialog saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(SimpleFileChooser.this); if (option == JFileChooser.APPROVE_OPTION) { statusbar.setText("You saved " + ((chooser.getSelectedFile() != null) ? chooser.getSelectedFile().getName() : "nothing")); } else { statusbar.setText("You canceled."); } } }); // Create a file chooser that allows you to pick a directory // rather than a file dirButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int option = chooser.showOpenDialog(SimpleFileChooser.this); if (option == JFileChooser.APPROVE_OPTION) { statusbar.setText("You opened " + ((chooser.getSelectedFile() != null) ? chooser.getSelectedFile().getName() : "nothing")); } else { statusbar.setText("You canceled."); } } }); c.add(openButton); c.add(saveButton); c.add(dirButton); c.add(statusbar); }