本文整理汇总了Java中javax.swing.JFileChooser.setSelectedFiles方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.setSelectedFiles方法的具体用法?Java JFileChooser.setSelectedFiles怎么用?Java JFileChooser.setSelectedFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.setSelectedFiles方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: browseLibraryButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void browseLibraryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLibraryButtonActionPerformed
JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastChosenLibraryLocation());
File[] olds = convertStringToFiles(txtLibrary.getText().trim());
chooser.setSelectedFiles(olds);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(true);
chooser.addChoosableFileFilter(new JarZipFilter());
int ret = chooser.showDialog(this, getMessage("LBL_Select"));
if (ret == JFileChooser.APPROVE_OPTION) {
File[] files = chooser.getSelectedFiles();
if (files.length == 0) {
return;
}
String path = "";
for (int i = 0; i < files.length; i++) {
path = path + files[i] + ( i == files.length - 1 ? "" : File.pathSeparator);
}
txtLibrary.setText(path);
ModuleUISettings.getDefault().setLastChosenLibraryLocation(files[0].getParentFile().getAbsolutePath());
}
}
示例2: actionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public @Override void actionPerformed(ActionEvent evt) {
JFileChooser chooser = ProjectChooserAccessory.createProjectChooser( true ); // Create the jFileChooser
chooser.setMultiSelectionEnabled( true );
// Check to see if the current selection matches a file/folder owned by a non-open project;
// if so, use that as the starting directory, as a convenience in case that is what should be opened.
// XXX may also want to check lookup for FileObject
for (DataObject d : Utilities.actionsGlobalContext().lookupAll(DataObject.class)) {
Project selected = FileOwnerQuery.getOwner(d.getPrimaryFile());
if (selected != null && !OpenProjectList.getDefault().isOpen(selected)) {
File dir = FileUtil.toFile(selected.getProjectDirectory());
if (dir != null) {
chooser.setCurrentDirectory(dir.getParentFile());
chooser.setSelectedFiles(new File[] {dir});
break;
}
}
}
show(chooser);
}
示例3: actionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
if (UIManager.getBoolean("FileChooser.readOnly")) {
return;
}
JFileChooser fc = getFileChooser();
File currentDirectory = fc.getCurrentDirectory();
FileSystemView fsv = fc.getFileSystemView();
File newFolder = null;
String name = SwingTools.showInputDialog("file_chooser.new_folder", "");
try {
if (name != null && !"".equals(name)) {
newFolder = fsv.createNewFolder(currentDirectory);
if (newFolder.renameTo(fsv.createFileObject(fsv.getParentDirectory(newFolder), name))) {
newFolder = fsv.createFileObject(fsv.getParentDirectory(newFolder), name);
} else {
SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.rename", name);
}
}
} catch (IOException exc) {
SwingTools.showVerySimpleErrorMessage("file_chooser.new_folder.create", name);
return;
} catch (Exception exp) {
// do nothing
}
if (fc.isMultiSelectionEnabled()) {
fc.setSelectedFiles(new File[] { newFolder });
} else {
fc.setSelectedFile(newFolder);
}
fc.rescanCurrentDirectory();
}
示例4: marathon_select
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override public boolean marathon_select(String value) {
JFileChooser fc = (JFileChooser) component;
if (value.equals("")) {
fc.cancelSelection();
return true;
}
if (fc.isMultiSelectionEnabled()) {
fc.setSelectedFiles(ChooserHelper.decode(value));
fc.approveSelection();
return true;
}
fc.setSelectedFile(ChooserHelper.decodeFile(value));
fc.approveSelection();
return true;
}
示例5: save
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Shows a file chooser and exports the plot to the selected image file.
* @throws IOException if an error occurs during writing.
*/
public void save() throws IOException {
JFileChooser fc = FileChooser.getInstance();
fc.setFileFilter(FileChooser.SimpleFileFilter.getWritableImageFIlter());
fc.setAcceptAllFileFilterUsed(false);
fc.setSelectedFiles(new File[0]);
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
save(file);
}
}