本文整理汇总了Java中javax.swing.JFileChooser.setFileFilter方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.setFileFilter方法的具体用法?Java JFileChooser.setFileFilter怎么用?Java JFileChooser.setFileFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.setFileFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doLoadApsDvsNetworkFromXML
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Loads a convolutional neural network (CNN) trained using DeapLearnToolbox
* for Matlab (https://github.com/rasmusbergpalm/DeepLearnToolbox) that was
* exported using Danny Neil's XML Matlab script cnntoxml.m.
*
*/
synchronized public void doLoadApsDvsNetworkFromXML() {
JFileChooser c = new JFileChooser(lastApsDvsNetXMLFilename);
FileFilter filt = new FileNameExtensionFilter("XML File", "xml");
c.addChoosableFileFilter(filt);
c.setFileFilter(filt);
c.setSelectedFile(new File(lastApsDvsNetXMLFilename));
int ret = c.showOpenDialog(chip.getAeViewer());
if (ret != JFileChooser.APPROVE_OPTION) {
return;
}
lastApsDvsNetXMLFilename = c.getSelectedFile().toString();
putString("lastAPSNetXMLFilename", lastApsDvsNetXMLFilename);
try {
apsDvsNet.loadFromXMLFile(c.getSelectedFile());
dvsSubsampler = new DvsFramerSingleFrame(chip);
dvsSubsampler.setFromNetwork(apsDvsNet);
} catch (Exception ex) {
Logger.getLogger(DavisDeepLearnCnnProcessor_HJ.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't load net from this file, caught exception " + ex + ". See console for logging.", "Bad network file", JOptionPane.WARNING_MESSAGE);
}
}
示例2: openFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Open a file.
*/
protected void openFile() {
JFileChooser jc = new JFileChooser();
String pathName = userPreferences.getDiskImageDirectory();
if (null == pathName) {
pathName = ""; //$NON-NLS-1$
}
jc.setCurrentDirectory(new File(pathName));
EmulatorFileFilter ff = new EmulatorFileFilter();
jc.setFileFilter(ff);
int rc = jc.showDialog(this, textBundle.get("Open")); //$NON-NLS-1$
if (rc == 0) {
userPreferences.setDiskImageDirectory(jc.getSelectedFile().getParent());
UserPreferences.getInstance().save();
addDiskExplorerTab(jc.getSelectedFile());
}
}
示例3: openFileDialogAndGetFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private File openFileDialogAndGetFile(String tip, String key, String type, String... ext) {
File file = null;
JFileChooser c = new JFileChooser(lastNetworkFilename);
File f = new File(lastNetworkFilename);
c.setCurrentDirectory(new File(getString("lastNetworkPathname", "")));
c.setToolTipText(tip);
FileFilter filt = new FileNameExtensionFilter(type, ext);
c.addChoosableFileFilter(filt);
c.setFileFilter(filt);
c.setSelectedFile(new File(lastNetworkFilename));
int ret = c.showOpenDialog(chip.getAeViewer());
if (ret != JFileChooser.APPROVE_OPTION) {
return null;
}
lastNetworkFilename = c.getSelectedFile().toString();
putString(key, lastNetworkFilename);
lastNetworkPathname = f.getPath();
putString("lastNetworkPathname", lastNetworkPathname);
file = c.getSelectedFile();
return file;
}
示例4: nativeIconButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void nativeIconButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nativeIconButtonActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(null);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new IconFileFilter(false));
String current = nativeIconTextField.getText();
File lastFolder = current!=null ? getFileFromPath(current) : null;
if (lastFolder != null) {
chooser.setSelectedFile(lastFolder);
} else if (lastImageFolder != null) {
chooser.setSelectedFile(lastImageFolder);
} else { // ???
// workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
// chooser.setSelectedFile(new File(workDir));
}
chooser.setDialogTitle(NbBundle.getMessage(JFXIconsPanel.class, "LBL_Select_Icon_Image")); // NOI18N
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
File file = FileUtil.normalizeFile(chooser.getSelectedFile());
String relPath = JFXProjectUtils.getRelativePath(project.getProjectDirectory(), FileUtil.toFileObject(file));
nativeIconTextField.setText(relPath);
lastImageFolder = file;
}
}
示例5: chooseButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void chooseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseButtonActionPerformed
JFileChooser chooser = new JFileChooser(new FXMLTemplateWizardIterator.SrcFileSystemView(support.getSourceGroupsAsFiles()));
chooser.setDialogTitle(NbBundle.getMessage(ConfigureFXMLControllerPanelVisual.class, "LBL_ConfigureFXMLPanel_FileChooser_Select_Controller")); // NOI18N
chooser.setFileFilter(FXMLTemplateWizardIterator.FXMLTemplateFileFilter.createJavaFilter());
String existingPath = existingNameTextField.getText();
if (existingPath.length() > 0) {
File f = new File(support.getCurrentChooserFolder().getPath() + File.pathSeparator + existingPath);
if (f.exists()) {
chooser.setSelectedFile(f);
} else {
chooser.setCurrentDirectory(FileUtil.toFile(support.getCurrentChooserFolder()));
}
} else {
chooser.setCurrentDirectory(FileUtil.toFile(support.getCurrentChooserFolder()));
}
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
String controllerClass = FileUtil.normalizeFile(chooser.getSelectedFile()).getPath();
// XXX check other roots ?
final String srcPath = FileUtil.normalizeFile(FileUtil.toFile(support.getCurrentSourceGroupFolder())).getPath();
final String relativePath = controllerClass.substring(srcPath.length() + 1);
final String relativePathWithoutExt = relativePath.substring(0, relativePath.indexOf(FXMLTemplateWizardIterator.JAVA_FILE_EXTENSION));
existingNameTextField.setText(relativePathWithoutExt.replace(File.separatorChar, '.')); // NOI18N
}
}
示例6: initCxfNetwork
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public void initCxfNetwork(CxfNetwork cxfNetwork) {
JFileChooser fc = new FileChooser();
fc.setDialogTitle("Select a CXF file");
fc.setFileFilter(new FileNameExtensionFilter(".cxf files", "cxf"));
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
ch.ethz.sg.cuttlefish.gui2.Cuttlefish.currentDirectory = fc.getCurrentDirectory();
System.out.println("Current directory: " + fc.getCurrentDirectory());
File file = fc.getSelectedFile();
cxfNetwork.load(file);
cxfNetwork.setNetworkLoaded(true);
} else {
System.out.println("Input cancelled by user");
}
}
示例7: getFileChooser
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private JFileChooser getFileChooser() {
if (fileChooser == null) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(false);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
chooser.setDialogTitle(Bundle.LocationCustomizer_ChooseFileDialogCaption());
chooser.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(".java");
} // NOI18N
public String getDescription() {
return Bundle.LocationCustomizer_FileDialogFilterName();
}
});
fileChooser = chooser;
}
return fileChooser;
}
示例8: openFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void openFile() {
JFileChooser file = new JFileChooser();
file.setAcceptAllFileFilterUsed(false);
file.setFileFilter(new FileNameExtensionFilter("xml files (*.xml)", "xml"));
if (lastCurrentDirectory != null)
file.setCurrentDirectory(lastCurrentDirectory);
if (file.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
txtFilePath.setText(file.getSelectedFile().getAbsolutePath());
lastCurrentDirectory = file.getSelectedFile();
openXML();
}
}
示例9: bSeleniumServerJarActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void bSeleniumServerJarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSeleniumServerJarActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileNameExtensionFilter("Jar File", "jar"));
chooser.setSelectedFile(new File(tfSeleniumServerJar.getText().trim()));
if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
tfSeleniumServerJar.setText(chooser.getSelectedFile().getAbsolutePath());
updateValidity();
}
}
示例10: addItem
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void addItem() {
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(fileFilter);
int r = chooser.showOpenDialog(this);
if (r == JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
Item item = new Item();
item.fileName = f.getAbsolutePath();
items.add(item);
model.fireTableRowsInserted(items.size() - 1, items.size() - 1);
}
}
示例11: saveAsExcel
import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected void saveAsExcel(Iterator it) {
JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
ExcelFileFilter eff = new ExcelFileFilter();
jfc.setFileFilter(eff);
File f=new File("PDB_Export.xls");
jfc.setSelectedFile(f);
do {
int c = jfc.showSaveDialog(null);
if (c==jfc.CANCEL_OPTION||c==jfc.ERROR_OPTION) return;
f = jfc.getSelectedFile();
if (f.exists()) {
c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
if (c==JOptionPane.OK_OPTION) break;
if (c==JOptionPane.CANCEL_OPTION) return;
}
} while (f.exists());
try {
WritableWorkbook wb = Workbook.createWorkbook(f);
WritableSheet sheet = wb.createSheet("First Sheet", 0);
int r = 0;
while (it.hasNext()) {
String[] split = it.next().toString().split("\\t");
for (int i = 0; i < split.length; i++)
sheet.addCell( new Label(i,r,split[i]) );
r++;
}
wb.write();
wb.close();
} catch (Exception ex){
}
}
示例12: getFileFromDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private static File getFileFromDialog() {
JFileChooser fc = new JFileChooser();
int returnVal;
fc.setDialogType(JFileChooser.OPEN_DIALOG);
//set a default filename
fc.setSelectedFile(new File("emitters.csv"));
//Set an extension filter
fc.setFileFilter(new FileNameExtensionFilter("CSV file","csv"));
returnVal = fc.showOpenDialog(null);
if (returnVal != JFileChooser.APPROVE_OPTION) {
throw new RuntimeException("You need to select an emitter file!");
}
return fc.getSelectedFile();
}
示例13: openAEInputFileDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/** this call shows a file chooser for index files: files containing
* information on which AE data files go together. This method is only called when an index file is opened.
*/
public void openAEInputFileDialog() {
fileChooser = new JFileChooser();
IndexFileFilter filter = new IndexFileFilter();
String lastFilePath = prefs.get("JAERViewer.lastFile", "");
// get the last folder
lastFile = new File(lastFilePath);
fileChooser.setFileFilter(filter);
fileChooser.setCurrentDirectory(lastFile);
// sets the working directory of the chooser
// boolean wasPaused=isPaused();
setPaused(true);
int retValue = fileChooser.showOpenDialog(null);
if (retValue == JFileChooser.APPROVE_OPTION) {
try {
lastFile = fileChooser.getSelectedFile();
// if(lastFile!=null) recentFiles.addFile(lastFile);
startPlayback(lastFile);
lastFilePath = lastFile.getPath();
prefs.put("JAERViewer.lastFile", lastFilePath);
} catch (IOException fnf) {
fnf.printStackTrace();
}
}
fileChooser = null;
setPaused(false);
}
示例14: buttonSelected
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
protected void buttonSelected()
{
JFileChooser chooser = new JFileChooser(currentDirectory);
chooser.setMultiSelectionEnabled(false);
chooser.setFileSelectionMode(selectionMode);
chooser.setFileFilter(filter);
int result = chooser.showOpenDialog(this);
if( result == JFileChooser.APPROVE_OPTION )
{
setSelectedFile(chooser.getSelectedFile());
}
}
示例15: filterUI
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
public File[] filterUI() {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JSON Files", "json");
chooser.setFileFilter(filter);
chooser.setMultiSelectionEnabled(true);
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
return chooser.getSelectedFiles();
} else {
return null;
}
}