本文整理了Java中javax.swing.JFileChooser.setSelectedFiles()
方法的一些代码示例,展示了JFileChooser.setSelectedFiles()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFileChooser.setSelectedFiles()
方法的具体详情如下:
包路径:javax.swing.JFileChooser
类名称:JFileChooser
方法名:setSelectedFiles
暂无
代码示例来源:origin: org.gephi/directory-chooser
private void setSelected(File[] files) {
changeDirectory = false;
fileChooser.setSelectedFiles(files);
changeDirectory = true;
}
代码示例来源:origin: UISpec4J/UISpec4J
public void process(JFileChooser fileChooser) {
fileChooser.setSelectedFiles(files);
}
});
代码示例来源:origin: eu.mihosoft.vrl/vrl
@Override
public void setSelectedFiles(File[] selectedFiles) {
super.setSelectedFiles(selectedFiles);
// if (!nativeDialogsShallBeUsed()) {
// super.setSelectedFiles(selectedFiles);
// return;
// }
// if (selectedFiles == null || selectedFiles.length == 0) {
// currentFiles = null;
// } else {
// setSelectedFile(selectedFiles[0]);
// currentFiles = new ArrayList<>(Arrays.asList(selectedFiles));
// }
}
代码示例来源:origin: tinyMediaManager/tinyMediaManager
@Override
public void setSelectedFiles(File[] selectedFiles) {
if (!JAVAFX_AVAILABLE) {
super.setSelectedFiles(selectedFiles);
return;
}
if (selectedFiles == null || selectedFiles.length == 0) {
currentFiles = null;
}
else {
setSelectedFile(selectedFiles[0]);
currentFiles = new ArrayList<>(Arrays.asList(selectedFiles));
}
}
代码示例来源:origin: stackoverflow.com
final JFileChooser c = new JFileChooser();
c.setMultiSelectionEnabled(true);
c.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
c.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (JFileChooser.SELECTED_FILES_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
File[] selectedFiles = c.getSelectedFiles();
if (selectedFiles.length > 1) {
File f=c.getSelectedFile();
if (f.isDirectory())
c.setSelectedFiles(new File[] {f});
}
}
}
});
c.showDialog(null,"Apply");
System.out.println(Arrays.asList(c.getSelectedFiles()));
代码示例来源:origin: com.l2fprod.common/l2fprod-common-directorychooser
private void setSelectedFiles() {
TreePath[] selectedPaths = tree.getSelectionPaths();
if (selectedPaths == null || selectedPaths.length == 0) {
chooser.setSelectedFile(null);
return;
}
List files = new ArrayList();
for (int i = 0, c = selectedPaths.length; i < c; i++) {
LazyMutableTreeNode node = (LazyMutableTreeNode)selectedPaths[i]
.getLastPathComponent();
if (node instanceof FileTreeNode) {
File f = ((FileTreeNode)node).getFile();
files.add(f);
}
}
chooser.setSelectedFiles((File[])files.toArray(new File[0]));
}
代码示例来源:origin: syedlopez/proguard
public void actionPerformed(ActionEvent e)
{
chooser.setDialogTitle(msg("addJars"));
chooser.setSelectedFile(null);
chooser.setSelectedFiles(null);
int returnValue = chooser.showOpenDialog(owner);
if (returnValue == JFileChooser.APPROVE_OPTION)
{
File[] selectedFiles = chooser.getSelectedFiles();
ClassPathEntry[] entries = classPathEntries(selectedFiles, isOutput);
// Add the new elements.
addElements(entries);
}
}
});
代码示例来源:origin: org.gephi/directory-chooser
private void fireMultiSelectionChanged(PropertyChangeEvent e) {
if (getFileChooser().isMultiSelectionEnabled()) {
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
} else {
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
getFileChooser().setSelectedFiles(null);
}
}
代码示例来源:origin: orbisgis/orbisgis
public void setValue(String fieldName, String fieldValue) {
if (fieldName.equals(FIELD_NAME)) {
String[] files = fieldValue.split("\\Q||\\E");
File[] selectedFiles = new File[files.length];
for (int i = 0; i < selectedFiles.length; i++) {
selectedFiles[i] = new File(files[i]);
}
getFileChooser().setSelectedFiles(selectedFiles);
} else {
FileFilter[] filters = getFileChooser().getChoosableFileFilters();
for (FileFilter fileFilter : filters) {
if (fieldValue.equals(fileFilter.getDescription())) {
getFileChooser().setFileFilter(fileFilter);
}
}
}
}
代码示例来源:origin: com.github.haifengl/smile-plot
/**
* 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);
}
}
代码示例来源:origin: orbisgis/orbisgis
public void setValue(String fieldName, String fieldValue) {
if (fieldName.equals(FIELD_NAME)) {
String[] files = fieldValue.split("\\Q||\\E");
File[] selectedFiles = new File[files.length];
for (int i = 0; i < selectedFiles.length; i++) {
selectedFiles[i] = new File(files[i]);
}
getFileChooser().setSelectedFiles(selectedFiles);
} else {
FileFilter[] filters = getFileChooser().getChoosableFileFilters();
for (FileFilter fileFilter : filters) {
if (fieldValue.equals(fileFilter.getDescription())) {
getFileChooser().setFileFilter(fileFilter);
}
}
}
}
代码示例来源:origin: stackoverflow.com
allowedFiles[1] = selectedFiles[0];
fc.setSelectedFiles(allowedFiles);
代码示例来源:origin: com.github.haifengl/smile-plot
/**
* 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 {
FileChooser.SimpleFileFilter filter = FileChooser.SimpleFileFilter.getWritableImageFIlter();
JFileChooser chooser = FileChooser.getInstance();
chooser.setFileFilter(filter);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setSelectedFiles(new File[0]);
int returnVal = chooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
if (!filter.accept(file)) {
file = new File(file.getParentFile(), file.getName() + ".png");
}
save(file);
}
}
代码示例来源:origin: orbisgis/orbisgis
public void setValue(String fieldName, String fieldValue) {
if (fieldName.equals(FIELD_NAME)) {
String[] files = fieldValue.split("\\Q||\\E");
File[] selectedFiles = new File[files.length];
for (int i = 0; i < selectedFiles.length; i++) {
selectedFiles[i] = new File(files[i]);
}
getFileChooser().setSelectedFiles(selectedFiles);
} else {
FileFilter[] filters = getFileChooser().getChoosableFileFilters();
for (FileFilter fileFilter : filters) {
if (fieldValue.equals(fileFilter.getDescription())) {
getFileChooser().setFileFilter(fileFilter);
}
}
}
}
代码示例来源:origin: pentaho/pentaho-reporting
fileChooser.setSelectedFiles( selectedFiles );
fileChooser.updateUI();
fileChooser.resetChoosableFileFilters();
代码示例来源:origin: org.gephi/directory-chooser
chooser.firePropertyChange(JFileChooser.DIRECTORY_CHANGED_PROPERTY, false, true);
} else {
chooser.setSelectedFiles(new File[] {file});
chooser.setCurrentDirectory(file);
代码示例来源:origin: joel-costigliola/assertj-swing
@RunsInEDT
static void setSelectedFiles(final @Nonnull JFileChooser fileChooser, final @Nonnull File[] files) {
execute(() -> {
checkEnabledAndShowing(fileChooser);
if (files.length > 1 && !fileChooser.isMultiSelectionEnabled()) {
throw new IllegalStateException(concat("Expecting file chooser ", format(fileChooser),
" to handle multiple selection"));
}
for (File file : files) {
checkSelectionMode(fileChooser, file);
}
fileChooser.setSelectedFiles(files);
});
}
代码示例来源:origin: com.l2fprod.common/l2fprod-common-directorychooser
if (newFolder.mkdir()) {
if (fc.isMultiSelectionEnabled()) {
fc.setSelectedFiles(new File[] {newFolder});
} else {
fc.setSelectedFile(newFolder);
代码示例来源:origin: syedlopez/proguard
chooser.setSelectedFiles(selectedFiles);
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf
private void doMultiSelectionChanged(PropertyChangeEvent e)
{
if (getFileChooser().isMultiSelectionEnabled())
{
listSelectionModel.setSelectionMode(
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}
else
{
listSelectionModel.setSelectionMode(
ListSelectionModel.SINGLE_SELECTION);
listSelectionModel.clearSelection();
getFileChooser().setSelectedFiles(null);
}
}
内容来源于网络,如有侵权,请联系作者删除!