下面列出了javax.swing.JFileChooser#setDragEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
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;
}
}
/**
* 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;
}
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;
}
}