final JFileChooser chooser = new JFileChooser() { public void approveSelection() { if (getSelectedFile().isFile()) { return; } else super.approveSelection(); } }; chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES );
private void browseOutputDirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseOutputDirActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // System.out.println("Opening: " + file.getAbsolutePath()); tfOutputDir.setText(file.getAbsolutePath()); } }// GEN-LAST:event_browseOutputDirActionPerformed
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(rootDirectoryField.getText()); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.showDialog(frame, "Select"); if (fc.getSelectedFile() != null) { rootDirectoryField.setText(fc.getSelectedFile().getAbsolutePath()); } } }
/** * Do the stuff for this class (create the file) * * @throws Exception */ public static void main(String args[]) throws Exception { System.out.println("Starting..."); String wd = "./test"; // choose the directory to open JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(wd)); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File[] dirs = chooser.getSelectedFiles(); for (File directory : dirs) { System.out.println("Doing migration on directory: " + directory.getAbsolutePath()); doMigration(directory); } } }
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { // Add a directory final JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Select Image Directory"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) importFromDirectories(chooser.getSelectedFiles()); }
import java.io.File; import javax.swing.JFileChooser; public class ShowDirectoriesOnly { public static void main(String[] args) { JFileChooser fileChooser = new JFileChooser( "." ); fileChooser.setControlButtonsAreShown( false ); fileChooser.setFileFilter( new FolderFilter() ); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.showOpenDialog(null); } private static class FolderFilter extends javax.swing.filechooser.FileFilter { @Override public boolean accept( File file ) { return file.isDirectory(); } @Override public String getDescription() { return "We only take directories"; } } }
private void prepareFileChooser(JFileChooser chooser) { chooser.setFileSelectionMode(dirsOnly ? JFileChooser.DIRECTORIES_ONLY : filesOnly ? JFileChooser.FILES_ONLY : JFileChooser.FILES_AND_DIRECTORIES); chooser.setAcceptAllFileFilterUsed(useAcceptAllFileFilter); if (title != null) { chooser.setDialogTitle(title);
private void browseInputDirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseInputDirActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // System.out.println("Opening: " + file.getAbsolutePath()); tfInputDir.setText(file.getAbsolutePath()); } }// GEN-LAST:event_browseInputDirActionPerformed
@Override public void actionPerformed(final ActionEvent e) { final JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setAcceptAllFileFilterUsed(false); final int result = jfc.showSaveDialog(null); if (result == JFileChooser.APPROVE_OPTION) { txtTempFolder.setText(jfc.getSelectedFile().getAbsolutePath()); } } });
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { // Add a directory final JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Select Image Directory"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) importFromDirectories(chooser.getSelectedFiles()); }
JFileChooser j = new JFileChooser(); j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); Integer opt = j.showSaveDialog(this);
/** * Creates a {@code JFileChooser} component and sets it to be for directories only. * * @param parent the component from where the chooser will be launched <i>(should be the main panel of the application)</i>. */ public DirChooser(Component parent) { this.parent = parent; dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); dirChooser.setDialogTitle(String.format(I18n.INSTANCE.get("dirchooser.title"), Configuration.INSTANCE.get("application.name"))); dirChooser.setApproveButtonText(I18n.INSTANCE.get("dirchooser.approve.btn")); }
private void browseSoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseSoxActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // System.out.println("Opening: " + file.getAbsolutePath()); tfSoxPath.setText(file.getAbsolutePath()); } }// GEN-LAST:event_browseSoxActionPerformed
import javax.swing.*; public class Example { public static void main(String[] args) { JFileChooser f = new JFileChooser(); f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); f.showSaveDialog(null); System.out.println(f.getCurrentDirectory()); System.out.println(f.getSelectedFile()); } }
private JFileChooser createFileChooser(String... fileFilters) { JFileChooser fc = new JFileChooser(); for (String fileFilter : fileFilters) { fc.addChoosableFileFilter(new FileChooserFileFilter(fileFilter)); } fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); return fc; }
private void browseSoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseSoxActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // System.out.println("Opening: " + file.getAbsolutePath()); tfSoxPath.setText(file.getAbsolutePath()); } }// GEN-LAST:event_browseSoxActionPerformed
@Override public void actionPerformed(final ActionEvent e) { final JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setAcceptAllFileFilterUsed(true); final int result = jfc.showSaveDialog(null); if (result == JFileChooser.APPROVE_OPTION) { final String absolutePath = jfc.getSelectedFile().getAbsolutePath(); if (absolutePath.endsWith(".zip")) { txtDestination.setText(absolutePath); } else { txtDestination.setText(absolutePath + ".zip"); } } } });
public static JFileChooser getSettingsFileChooser() { FirmwareSettingsFileTypeFilter filter = new FirmwareSettingsFileTypeFilter(); // Setup file browser with the last path used. JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setFileHidingEnabled(true); fileChooser.addChoosableFileFilter(filter); fileChooser.setAcceptAllFileFilterUsed(true); fileChooser.setFileFilter(filter); return fileChooser; }
private void browseInputDirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseInputDirActionPerformed JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // System.out.println("Opening: " + file.getAbsolutePath()); tfInputDir.setText(file.getAbsolutePath()); } }// GEN-LAST:event_browseInputDirActionPerformed
private void jMenuItem_OpenActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem_OpenActionPerformed // Allow user to choose a different voice (prompt set) without exiting the tool // Create a file chooser final JFileChooser openDialog = new JFileChooser(); // Set the current directory to the voice currently in use openDialog.setCurrentDirectory(getVoiceFolderPath()); openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = openDialog.showDialog(AdminWindow.this, "Open Voice"); if (result == JFileChooser.APPROVE_OPTION) { File voice = openDialog.getSelectedFile(); setVoiceFolderPath(voice); // Set to the selected the voice folder path Test.output("Open voice: " + voice); setupVoice(); } else { Test.output("Open command cancelled."); } }// GEN-LAST:event_jMenuItem_OpenActionPerformed