本文整理了Java中javax.swing.JFileChooser.getFileFilter()
方法的一些代码示例,展示了JFileChooser.getFileFilter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFileChooser.getFileFilter()
方法的具体详情如下:
包路径:javax.swing.JFileChooser
类名称:JFileChooser
方法名:getFileFilter
暂无
代码示例来源:origin: chewiebug/GCViewer
@Override
public void actionPerformed(final ActionEvent e) {
final GCDocument gcDocument = gcViewer.getSelectedGCDocument();
for (int i=0; i<gcDocument.getChartPanelViewCount(); i++) {
final ChartPanelView chartPanelView = gcDocument.getChartPanelView(i);
final File file = new File(chartPanelView.getGCResource().getResourceName());
saveDialog.setCurrentDirectory(file.getParentFile());
saveDialog.setSelectedFile(file);
final int val = saveDialog.showSaveDialog(gcViewer);
if (val == JFileChooser.APPROVE_OPTION) {
ExportExtensionFileFilter fileFilter = (ExportExtensionFileFilter) saveDialog.getFileFilter();
// On OS/X if you don't select one of the filters and just press "Save" the filter may be null. Use the CSV one then
if (fileFilter==null) {
fileFilter = (ExportExtensionFileFilter) saveDialog.getChoosableFileFilters()[0];
}
exportFile(chartPanelView.getGCResource().getModel(),
saveDialog.getSelectedFile(),
fileFilter.getExtension(),
fileFilter.getDataWriterType());
}
else if (val == JFileChooser.ERROR_OPTION) {
JOptionPane.showMessageDialog(gcViewer, LocalisationHelper.getString("fileexport_dialog_error_occured"), LocalisationHelper.getString("fileexport_dialog_write_file_failed"), JOptionPane.ERROR_MESSAGE);
}
}
}
代码示例来源:origin: knowm/XChart
File theFileToSave = fileChooser.getSelectedFile();
try {
if (fileChooser.getFileFilter() == null) {
BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.PNG);
} else if (fileChooser.getFileFilter().getDescription().equals("*.jpg,*.JPG")) {
BitmapEncoder.saveJPGWithQuality(
chart,
BitmapEncoder.addFileExtension(theFileToSave.getCanonicalPath(), BitmapFormat.JPG),
1.0f);
} else if (fileChooser.getFileFilter().getDescription().equals("*.png,*.PNG")) {
BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.PNG);
} else if (fileChooser.getFileFilter().getDescription().equals("*.bmp,*.BMP")) {
BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.BMP);
} else if (fileChooser.getFileFilter().getDescription().equals("*.gif,*.GIF")) {
BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath(), BitmapFormat.GIF);
} else if (fileChooser.getFileFilter().getDescription().equals("*.svg,*.SVG")) {
VectorGraphicsEncoder.saveVectorGraphic(
chart, theFileToSave.getCanonicalPath(), VectorGraphicsFormat.SVG);
} else if (fileChooser.getFileFilter().getDescription().equals("*.eps,*.EPS")) {
VectorGraphicsEncoder.saveVectorGraphic(
chart, theFileToSave.getCanonicalPath(), VectorGraphicsFormat.EPS);
} else if (fileChooser.getFileFilter().getDescription().equals("*.pdf,*.PDF")) {
VectorGraphicsEncoder.saveVectorGraphic(
chart, theFileToSave.getCanonicalPath(), VectorGraphicsFormat.PDF);
代码示例来源:origin: net.anwiba.commons/anwiba-commons-swing-core
@Override
public FileFilter getFileFilter() {
return fileChooser.getFileFilter();
}
代码示例来源:origin: orbisgis/orbisgis
/**
* Return the identifier of the current filter
* @return The filter identifier, given by FileFilter.hashCode()
* @see setCurrentFilter
*/
public int getCurrentFilterId() {
return fileChooser.getFileFilter().hashCode();
}
/**
代码示例来源:origin: net.sf.squirrel-sql/squirrel-sql
public String getSelectedFileEnding()
{
return _fileAppenixes.get(_fileChooser.getFileFilter());
}
代码示例来源:origin: realXuJiang/bigtable-sql
public String getSelectedFileEnding()
{
return _fileAppenixes.get(_fileChooser.getFileFilter());
}
代码示例来源:origin: orbisgis/orbisgis
/**
* Returns the selected file filter.
* @return The selected file filter.
*/
public FileFilter getSelectedFilter() {
return getFileChooser().getFileFilter();
}
代码示例来源:origin: stackoverflow.com
//config fileChooser
JFileChooser fc = new JFileChooser(lastOpenDir);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setDialogTitle("Load Beacon List");
fc.removeChoosableFileFilter(fc.getFileFilter()); //remove the default file filter
FileFilter filter = new FileNameExtensionFilter("EXE file", "exe");
fc.addChoosableFileFilter(filter); //add XML file filter
//show dialog
int returnVal = fc.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION){
File selectedDir = fc.getSelectedFile();
...
代码示例来源:origin: cpesch/RouteConverter
private void setFormatFileFilters(JFileChooser chooser, List<NavigationFormat> formats, String selectedFormat) {
chooser.resetChoosableFileFilters();
FileFilter fileFilter = chooser.getFileFilter();
for (NavigationFormat format : formats) {
NavigationFormatFileFilter navigationFormatFileFilter = new NavigationFormatFileFilter(format);
if (format.getClass().getName().equals(selectedFormat))
fileFilter = navigationFormatFileFilter;
chooser.addChoosableFileFilter(navigationFormatFileFilter);
}
chooser.setFileFilter(fileFilter);
}
代码示例来源:origin: sdedit/sdedit
public static void suggestName(JFileChooser fileChooser, String basename) {
String name = basename;
FileFilter ff = fileChooser.getFileFilter();
if (ff instanceof FF) {
name = name + "." + ((FF) ff).getExtension().toLowerCase();
}
File file = new File(fileChooser.getCurrentDirectory(), name);
fileChooser.setSelectedFile(file);
}
代码示例来源:origin: stackoverflow.com
JFileChooser fileChooser = new JFileChooser("");
// Prevent user to use the default All Files option
fileChooser.setAcceptAllFileFilterUsed(false);
[...]
// Get the FileFilter
FileFilter ff = fileChooser.getFileFilter();
// Cast the FileFilter to FileNameExtensionFilter
FileNameExtensionFilter extFilter = (FileNameExtensionFilter)ff;
// Get the Extension
String ext = extFilter.getExtensions()[0];
代码示例来源:origin: orbisgis/orbisgis
private File autoComplete(File selectedFile) {
FileFilter ff = getFileChooser().getFileFilter();
if (ff instanceof FormatFilter) {
FormatFilter filter = (FormatFilter) ff;
return filter.autoComplete(selectedFile);
} else {
return selectedFile;
}
}
代码示例来源:origin: orbisgis/orbisgis
private File autoComplete(File selectedFile) {
FileFilter ff = getFileChooser().getFileFilter();
if (ff instanceof FormatFilter) {
FormatFilter filter = (FormatFilter) ff;
return filter.autoComplete(selectedFile);
} else {
return selectedFile;
}
}
代码示例来源:origin: org.gephi/directory-chooser
@Override
public Object getElementAt(int index) {
if(index > getSize() - 1) {
// This shouldn't happen. Try to recover gracefully.
return getFileChooser().getFileFilter();
}
if(filters != null) {
return filters[index];
} else {
return null;
}
}
}
代码示例来源:origin: antlr/antlrworks
private String getExtension(List extensions, JFileChooser chooser) {
if(extensions != null && extensions.size() >= 0) {
FileFilter ff = chooser.getFileFilter();
if(ff instanceof XJFileFilter) {
XJFileFilter filter = (XJFileFilter)ff;
if(!filter.accept(selectedFilePath))
return filter.getDefaultExtension();
}
}
return XJUtils.getPathExtension(selectedFilePath);
}
代码示例来源:origin: com.anrisoftware.prefdialog/prefdialog-misc-swing
@Override
public void openDialog(Component parent) throws PropertyVetoException {
int result = chooser.showOpenDialog(parent);
if (result == JFileChooser.APPROVE_OPTION) {
setFileFilter(chooser.getFileFilter());
setFile(chooser.getSelectedFile());
} else {
setFileFilter(null);
setFile(null);
}
}
代码示例来源:origin: com.anrisoftware.prefdialog/prefdialog-misc-swing
@Override
public void openDialog(Component parent) throws PropertyVetoException {
int result = chooser.showSaveDialog(parent);
if (result == JFileChooser.APPROVE_OPTION) {
setFileFilter(chooser.getFileFilter());
setFile(chooser.getSelectedFile());
} else {
setFileFilter(null);
setFile(null);
}
}
代码示例来源:origin: sing-group/GC4S
private void onBrowse() {
JFileChooser fileChooser = getConfiguredFileChooser();
int returnVal = mode.equals(Mode.SAVE) ?
fileChooser.showSaveDialog(JFileChooserPanel.this) :
fileChooser.showOpenDialog(JFileChooserPanel.this);
saveLastFileFilter(fileChooser.getFileFilter());
if (returnVal == JFileChooser.APPROVE_OPTION) {
setSelectedFile(fileChooser.getSelectedFile());
}
this.clearFileChooser();
}
代码示例来源:origin: sing-group/GC4S
private void onBrowse() {
JFileChooser fileChooser = getConfiguredFileChooser();
int returnVal = mode.equals(Mode.SAVE) ?
fileChooser.showSaveDialog(JMultipleFileChooserPanel.this) :
fileChooser.showOpenDialog(JMultipleFileChooserPanel.this);
saveLastFileFilter(fileChooser.getFileFilter());
if (returnVal == JFileChooser.APPROVE_OPTION) {
setSelectedFiles(fileChooser.getSelectedFiles());
}
this.clearFileChooser();
}
代码示例来源:origin: bcdev/beam
public void actionPerformed(ActionEvent e) {
final BeamFileFilter fileFilter = (BeamFileFilter) fileChooser.getFileFilter();
final ImageLegendDialog dialog = new ImageLegendDialog(visatApp,
legendParamGroup,
imageLegend,
isTransparencySupportedByFormat(
fileFilter.getFormatName()));
dialog.show();
}
});
内容来源于网络,如有侵权,请联系作者删除!