Java Code Examples for javax.swing.JFileChooser#setDragEnabled()

The following examples show how to use javax.swing.JFileChooser#setDragEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileChooserDemo.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
/**
    * Creates the file chooser.
    *
    * @return the j file chooser
    */
   public JFileChooser createFileChooser() {
// create a filechooser
JFileChooser fc = new JFileChooser();
       if (getSwingSet2() != null && getSwingSet2().isDragEnabled()) {
           fc.setDragEnabled(true);
       }

// set the current directory to be the images directory
File swingFile = new File("resources/images/About.jpg");
if(swingFile.exists()) {
    fc.setCurrentDirectory(swingFile);
    fc.setSelectedFile(swingFile);
}

return fc;
   }
 
Example 2
Source File: Utils.java    From j-j-jvm with Apache License 2.0 6 votes vote down vote up
public static File selectFileForSave(final Component parent, final FileFilter fileFiltere, final String title, final File initFile) {
  final JFileChooser chooser = new JFileChooser();
  chooser.setMultiSelectionEnabled(false);
  chooser.setDragEnabled(false);
  chooser.setControlButtonsAreShown(true);
  chooser.setDialogType(JFileChooser.SAVE_DIALOG);
  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  chooser.setFileFilter(fileFiltere);
  chooser.setDialogTitle(title);
  chooser.setAcceptAllFileFilterUsed(false);

  if (initFile != null) {
    chooser.setSelectedFile(initFile);
  }

  if (chooser.showDialog(parent, "Save") == JFileChooser.APPROVE_OPTION) {
    final File file = chooser.getSelectedFile();
    return file;
  } else {
    return null;
  }
}
 
Example 3
Source File: Utilities.java    From log-requests-to-sqlite with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create and configure a UI to select a DB file
 * @return a instance of a JFileChooser ready to use
 */
static JFileChooser createDBFileChooser() {
    JFileChooser customStoreFileNameFileChooser = new JFileChooser();
    customStoreFileNameFileChooser.setDialogTitle("Select the DB file to use...");
    customStoreFileNameFileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
    customStoreFileNameFileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    customStoreFileNameFileChooser.setDragEnabled(false);
    customStoreFileNameFileChooser.setMultiSelectionEnabled(false);
    customStoreFileNameFileChooser.setAcceptAllFileFilterUsed(false);
    customStoreFileNameFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    customStoreFileNameFileChooser.setFileHidingEnabled(true);
    return customStoreFileNameFileChooser;
}
 
Example 4
Source File: Utils.java    From j-j-jvm with Apache License 2.0 5 votes vote down vote up
public static File selectFileForOpen(final Component parent, final FileFilter[] fileFilters, final String title, final FileFilter[] selectedFilters, final File initFile) {
  JFileChooser chooser = new JFileChooser();
  chooser.setMultiSelectionEnabled(false);
  chooser.setDragEnabled(false);
  chooser.setControlButtonsAreShown(true);
  chooser.setDialogType(JFileChooser.OPEN_DIALOG);
  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

  for (final FileFilter fileFilter : fileFilters) {
    chooser.addChoosableFileFilter(fileFilter);
  }

  chooser.setDialogTitle(title);
  chooser.setAcceptAllFileFilterUsed(false);

  if (initFile != null) {
    chooser.setCurrentDirectory(initFile);
    chooser.setName(initFile.getName());
  }

  int returnVal = chooser.showDialog(parent, "Open");
  selectedFilters[0] = chooser.getFileFilter();

  if (returnVal == JFileChooser.APPROVE_OPTION) {
    File p_file = chooser.getSelectedFile();
    return p_file;
  } else {
    return null;
  }

}