本文整理汇总了Java中javax.swing.JFileChooser.addChoosableFileFilter方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.addChoosableFileFilter方法的具体用法?Java JFileChooser.addChoosableFileFilter怎么用?Java JFileChooser.addChoosableFileFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.addChoosableFileFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: loadFromXML
import javax.swing.JFileChooser; //导入方法依赖的package包/类
synchronized public void loadFromXML() {
this.setProcessingEnabled(false);
JFileChooser c = new JFileChooser(this.getLastRNNXMLFile());
FileFilter filter = new FileNameExtensionFilter("XML File", "xml");
c.addChoosableFileFilter(filter);
c.setFileFilter(filter);
c.setSelectedFile(new File(this.getLastRNNXMLFile()));
int ret = c.showOpenDialog(chip.getAeViewer());
if (ret != JFileChooser.APPROVE_OPTION) {
return;
}
File f = c.getSelectedFile();
try {
this.rnnetwork.loadFromXML(f);
this.setLastRNNXMLFile(f.toString());
putString("lastRNNXMLFile", this.getLastRNNXMLFile());
// this.testNumpyData.rnnetwork.loadFromXML(c.getSelectedFile()); //debug
} catch (Exception e) {
log.log(Level.WARNING, "Couldn't upload the xml file, please check. Caught exception {0}", e);
}
this.resetFilter();
}
示例3: mouseClicked
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
JFileChooser fileChooser = new JFileChooser(".");
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
String[] filterArr = new String[] {
".class", ".jar" };
FileFilter filter = new ExtensionFileFilter(null, filterArr);
fileChooser.addChoosableFileFilter(filter);
int selection = fileChooser.showOpenDialog(null);
if (selection == JFileChooser.APPROVE_OPTION) {
if (!fileChooser.getSelectedFile().isDirectory()||!recursive) {
File[] files = { fileChooser.getSelectedFile() };
listener.filesDropped(files);
} else {
listener.filesDropped(getAllFilesArray(fileChooser
.getSelectedFile(),filterArr));
}
}
if (selection == JFileChooser.CANCEL_OPTION) {
}
}
示例4: doSaveAs
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Opens a file chooser and gives the user an opportunity to save the chart
* in PNG format.
*
* @throws IOException if there is an I/O error.
*/
public void doSaveAs() throws IOException {
JFileChooser fileChooser = new JFileChooser();
ExtensionFileFilter filter = new ExtensionFileFilter(
localizationResources.getString("PNG_Image_Files"), ".png");
fileChooser.addChoosableFileFilter(filter);
int option = fileChooser.showSaveDialog(this);
if (option == JFileChooser.APPROVE_OPTION) {
String filename = fileChooser.getSelectedFile().getPath();
if (isEnforceFileExtensions()) {
if (!filename.endsWith(".png")) {
filename = filename + ".png";
}
}
ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
getWidth(), getHeight());
}
}
示例5: createFileChooser
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@NbBundle.Messages({
"ACTION_IdeSnapshot_dialog=Load IDE Snapshot",
"ACTION_IdeSnapshot_filter=IDE Snapshots"
})
private static JFileChooser createFileChooser(File directory) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(Bundle.ACTION_IdeSnapshot_dialog());
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (directory != null) {
chooser.setCurrentDirectory(directory);
}
String descr = Bundle.ACTION_IdeSnapshot_filter();
String ext = "."+ResultsManager.STACKTRACES_SNAPSHOT_EXTENSION; // NOI18N
Filter filter = Filter.create(descr, ext);
chooser.addChoosableFileFilter(filter);
return chooser;
}
示例6: createFileChooser
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private static JFileChooser createFileChooser() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setDialogTitle(Bundle.ExportSnapshotAction_FileChooserCaption());
fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
fileChooser.setApproveButtonText(Bundle.ExportSnapshotAction_ExportButtonText());
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
fileChooser.addChoosableFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().toLowerCase().endsWith(NPSS_EXT);
}
public String getDescription() {
return Bundle.ExportSnapshotAction_NpssFileFilter(NPSS_EXT);
}
});
return fileChooser;
}
示例7: 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);
}
}
示例8: createAndShowGUI
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private static void createAndShowGUI() {
fileChooser = new JFileChooser();
fileChooser.setAcceptAllFileFilterUsed(true);
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
FileFilter txtFilter = new FileNameExtensionFilter("Text files", "txt");
fileChooser.addChoosableFileFilter(txtFilter);
fileChooser.setFileFilter(txtFilter);
fileChooser.showOpenDialog(null);
}
示例9: openSound
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public void openSound(Frame frame)
{
JFileChooser fc = new JFileChooser();
fc.setSelectedFile(new File(lastOpenedSound));
fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory())
{
return true;
}
String extension = getExtension(f);
if (extension != null) {
if (extension.equals("wav"))
{
return true;
}
else
{
return false;
}
}
return false;
}
@Override
public String getDescription() {
return "Supported sound files (*.wav)";
}
});
int returnVal = fc.showDialog(frame, "Add sound");
if(returnVal == JFileChooser.APPROVE_OPTION)
{
loadSound(fc.getSelectedFile());
}
}
示例10: getFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Opens a file from disk.
*
* @param frame
* Parent frame.
* @return Opened file.
*/
public static File getFile(JVDraw frame) {
JFileChooser fc = new JFileChooser("./");
fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(new FileNameExtensionFilter(".jvd", "jvd"));
int status = fc.showSaveDialog(frame);
if (status == JFileChooser.OPEN_DIALOG) {
return setExtension(fc.getSelectedFile(), ".jvd");
}
return null;
}
示例11: importB_actionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
void importB_actionPerformed(ActionEvent e) {
// Fix until Sun's JVM supports more locales...
UIManager.put("FileChooser.lookInLabelText", Local
.getString("Look in:"));
UIManager.put("FileChooser.upFolderToolTipText", Local
.getString("Up One Level"));
UIManager.put("FileChooser.newFolderToolTipText", Local
.getString("Create New Folder"));
UIManager.put("FileChooser.listViewButtonToolTipText", Local
.getString("List"));
UIManager.put("FileChooser.detailsViewButtonToolTipText", Local
.getString("Details"));
UIManager.put("FileChooser.fileNameLabelText", Local
.getString("File Name:"));
UIManager.put("FileChooser.filesOfTypeLabelText", Local
.getString("Files of Type:"));
UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
UIManager.put("FileChooser.openButtonToolTipText", Local
.getString("Open selected file"));
UIManager
.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
UIManager.put("FileChooser.cancelButtonToolTipText", Local
.getString("Cancel"));
JFileChooser chooser = new JFileChooser();
chooser.setFileHidingEnabled(false);
chooser.setDialogTitle(Local.getString("Insert file"));
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
chooser.setPreferredSize(new Dimension(550, 375));
String lastSel = (String) Context.get("LAST_SELECTED_IMPORT_FILE");
if (lastSel != null)
chooser.setCurrentDirectory(new java.io.File(lastSel));
if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
return;
Context.put("LAST_SELECTED_IMPORT_FILE", chooser.getSelectedFile()
.getPath());
File f = chooser.getSelectedFile();
new HTMLFileImport(f, editor);
}
示例12: setIconB_actionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
void setIconB_actionPerformed(ActionEvent e) {
// Fix until Sun's JVM supports more locales...
UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");
JFileChooser chooser = new JFileChooser();
chooser.setPreferredSize(new Dimension(550, 375));
chooser.setFileHidingEnabled(false);
chooser.setDialogTitle(Local.getString("Choose icon file"));
//chooser.setAcceptAllFileFilterUsed(true);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setCurrentDirectory(
new File(net.sf.memoranda.ui.AppFrame.class.getResource("resources/icons/mimetypes").getPath()));
/*if (System.getProperty("os.name").startsWith("Win")) {
chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.ICO));
chooser.setCurrentDirectory(new File("C:\\Program Files"));
}
else */
chooser.addChoosableFileFilter(new net.sf.memoranda.ui.htmleditor.filechooser.ImageFilter());
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
iconLabel.setIcon(new ImageIcon(chooser.getSelectedFile().getPath()));
}
catch (Exception ex) {
//ex.printStackTrace();
}
finally {
iconPath = chooser.getSelectedFile().getPath();
}
}
}
示例13: actionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
*
*/
public void actionPerformed(ActionEvent e) {
BasicGraphEditor editor = getEditor(e);
if (editor != null) {
if (!editor.isModified() || JOptionPane.showConfirmDialog(editor,
mxResources.get("loseChanges")) == JOptionPane.YES_OPTION) {
mxGraph graph = editor.getGraphComponent().getGraph();
if (graph != null) {
String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir");
JFileChooser fc = new JFileChooser(wd);
// Adds file filter for supported file format
DefaultFileFilter defaultFilter = new DefaultFileFilter(".mxe",
mxResources.get("allSupportedFormats") + " (.mxe, .png, .vdx)") {
public boolean accept(File file) {
String lcase = file.getName().toLowerCase();
return super.accept(file) || lcase.endsWith(".png") || lcase.endsWith(".vdx");
}
};
fc.addChoosableFileFilter(defaultFilter);
fc.addChoosableFileFilter(new DefaultFileFilter(".mxe",
"mxGraph Editor " + mxResources.get("file") + " (.mxe)"));
fc.addChoosableFileFilter(
new DefaultFileFilter(".png", "PNG+XML " + mxResources.get("file") + " (.png)"));
// Adds file filter for VDX import
fc.addChoosableFileFilter(new DefaultFileFilter(".vdx",
"XML Drawing " + mxResources.get("file") + " (.vdx)"));
// Adds file filter for GD import
fc.addChoosableFileFilter(new DefaultFileFilter(".txt",
"Graph Drawing " + mxResources.get("file") + " (.txt)"));
fc.setFileFilter(defaultFilter);
int rc = fc.showDialog(null, mxResources.get("openFile"));
if (rc == JFileChooser.APPROVE_OPTION) {
lastDir = fc.getSelectedFile().getParent();
try {
if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".png")) {
openXmlPng(editor, fc.getSelectedFile());
} else if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".txt")) {
openGD(editor, fc.getSelectedFile(),
mxUtils.readFile(fc.getSelectedFile().getAbsolutePath()));
} else {
Document document =
mxXmlUtils.parseXml(mxUtils.readFile(fc.getSelectedFile().getAbsolutePath()));
mxCodec codec = new mxCodec(document);
codec.decode(document.getDocumentElement(), graph.getModel());
editor.setCurrentFile(fc.getSelectedFile());
resetEditor(editor);
}
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(editor.getGraphComponent(), ex.toString(),
mxResources.get("error"), JOptionPane.ERROR_MESSAGE);
}
}
}
}
}
}
示例14: createFileChooser
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private JFileChooser createFileChooser(File curentDir) {
final JFileChooser chooser = new AccessibleJFileChooser(NbBundle.getMessage(ExportDiffSupport.class, "ACSD_Export"));
chooser.setDialogTitle(NbBundle.getMessage(ExportDiffSupport.class, "CTL_Export_Title"));
chooser.setMultiSelectionEnabled(false);
javax.swing.filechooser.FileFilter[] old = chooser.getChoosableFileFilters();
for (int i = 0; i < old.length; i++) {
javax.swing.filechooser.FileFilter fileFilter = old[i];
chooser.removeChoosableFileFilter(fileFilter);
}
chooser.setCurrentDirectory(curentDir); // NOI18N
chooser.addChoosableFileFilter(getFileFilter());
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
chooser.setApproveButtonMnemonic(NbBundle.getMessage(ExportDiffSupport.class, "MNE_Export_ExportAction").charAt(0));
chooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String state = e.getActionCommand();
if (state.equals(JFileChooser.APPROVE_SELECTION)) {
File destination = chooser.getSelectedFile();
destination = getTargetFile(destination);
if (destination.exists()) {
NotifyDescriptor nd = new NotifyDescriptor.Confirmation(NbBundle.getMessage(ExportDiffSupport.class, "BK3005", destination.getAbsolutePath()));
nd.setOptionType(NotifyDescriptor.YES_NO_OPTION);
DialogDisplayer.getDefault().notify(nd);
if (nd.getValue().equals(NotifyDescriptor.OK_OPTION) == false) {
return;
}
}
preferences.put("ExportDiff.saveFolder", destination.getParent()); // NOI18N
panel.setOutputFileText(destination.getAbsolutePath());
} else {
dd.setValue(null);
}
if(dialog != null) {
dialog.dispose();
}
}
});
return chooser;
}
示例15: performContextAction
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
protected void performContextAction(Node[] nodes) {
VCSContext ctx = HgUtils.getCurrentContext(nodes);
final File roots[] = HgUtils.getActionRoots(ctx);
if (roots == null || roots.length == 0) {
return;
}
final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);
final JFileChooser fileChooser = new AccessibleJFileChooser(Bundle.ACSD_ApplyDiffPatchBrowseFolder(), null);
fileChooser.setDialogTitle(Bundle.ApplyDiffPatchBrowse_title());
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
fileChooser.setApproveButtonMnemonic(Bundle.ApplyDiffPatch_Apply().charAt(0));
fileChooser.setApproveButtonText(Bundle.ApplyDiffPatch_Apply());
fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
// setup filters, default one filters patch files
FileFilter patchFilter = new javax.swing.filechooser.FileFilter() {
@Override
public boolean accept(File f) {
return f.getName().endsWith("diff") || f.getName().endsWith("patch") || f.isDirectory(); // NOI18N
}
@Override
public String getDescription() {
return Bundle.CTL_PatchDialog_FileFilter();
}
};
fileChooser.addChoosableFileFilter(patchFilter);
fileChooser.setFileFilter(patchFilter);
DialogDescriptor dd = new DialogDescriptor(fileChooser, Bundle.ApplyDiffPatchBrowse_title());
dd.setOptions(new Object[0]);
final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
fileChooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String state = e.getActionCommand();
if (state.equals(JFileChooser.APPROVE_SELECTION)) {
final File patchFile = fileChooser.getSelectedFile();
final RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
new HgProgressSupport() {
@Override
protected void perform () {
if (isNetBeansPatch(patchFile)) {
PatchAction.performPatch(patchFile, roots[0]);
} else {
new ImportDiffAction.ImportDiffProgressSupport(root, patchFile, false, ImportDiffAction.ImportDiffProgressSupport.Kind.PATCH)
.start(rp, root, Bundle.MSG_ApplyDiffPatch_importingPatch());
}
}
}.start(rp, root, Bundle.MSG_ApplyDiffPatch_checkingFile());
}
dialog.dispose();
}
});
dialog.setVisible(true);
}