本文整理汇总了Java中javax.swing.JFileChooser.getCurrentDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.getCurrentDirectory方法的具体用法?Java JFileChooser.getCurrentDirectory怎么用?Java JFileChooser.getCurrentDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.getCurrentDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: btnNewFileBrowseActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void btnNewFileBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewFileBrowseActionPerformed
JFileChooser fc = new JFileChooser(wd);
FileFilter filter = new FileFilter() {
public boolean accept(File f) {
return f.getName().endsWith(".xml");
}
public String getDescription() {
return "XML files";
}
};
fc.setFileFilter(filter);
int result = fc.showOpenDialog(this);
if(result == JFileChooser.APPROVE_OPTION) {
txtNewFile.setText (fc.getSelectedFile().getPath());
wd = fc.getCurrentDirectory();
}
}
示例2: doDirectoryChanged
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void doDirectoryChanged(PropertyChangeEvent e) {
JFileChooser fc = getFileChooser();
FileSystemView fsv = fc.getFileSystemView();
clearIconCache();
File currentDirectory = fc.getCurrentDirectory();
this.fileList.updatePath(currentDirectory);
if (currentDirectory != null) {
this.directoryComboBoxModel.addItem(currentDirectory);
getNewFolderAction().setEnabled(currentDirectory.canWrite());
getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));
getChangeToParentDirectoryAction().setEnabled(!fsv.isRoot(currentDirectory));
getGoHomeAction().setEnabled(!userHomeDirectory.equals(currentDirectory));
if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
if (fsv.isFileSystem(currentDirectory)) {
setFileName(currentDirectory.getPath());
} else {
setFileName(null);
}
setFileSelected();
}
}
}
示例3: 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");
}
}
示例4: addFileButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void addFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFileButtonActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(true);
chooser.setDialogTitle(NbBundle.getMessage(SpringCustomizerPanel.class, "LBL_ChooseFile")); //NOI18N
chooser.setCurrentDirectory(basedir);
int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(groupFilesList));
if (option == JFileChooser.APPROVE_OPTION) {
boolean showDialog = false;
List<File> newFiles = new LinkedList<File>();
StringBuilder existing = new StringBuilder(
NbBundle.getMessage(SpringCustomizerPanel.class, "LBL_FileAlreadyAdded")).append("\n"); //NOI18N
for (File file : chooser.getSelectedFiles()) {
if (files.contains(file)) {
existing.append(file.getAbsolutePath()).append("\n"); //NOI18N
showDialog = true;
} else {
newFiles.add(file);
}
}
// remember last location
basedir = chooser.getCurrentDirectory();
addFiles(newFiles);
if (showDialog) {
DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(existing.toString(), NotifyDescriptor.ERROR_MESSAGE));
}
}
}
示例5: selectIconFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private File selectIconFile() {
JFileChooser dlg = new JFileChooser( defaultFolder );
dlg.setAcceptAllFileFilterUsed( true );
dlg.setMultiSelectionEnabled( false );
if( dlg.showOpenDialog(this) != JFileChooser.APPROVE_OPTION )
return null;
defaultFolder = dlg.getCurrentDirectory();
return dlg.getSelectedFile();
}
示例6: selectFileFromFileSystem
import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected static String selectFileFromFileSystem(JPanel panel,
File projDir,
String type){
File file = null;
String ret = null;
File lastBrowsed = getLastBrowsedDir(type);
JFileChooser jfc = new JFileChooser();
if (lastBrowsed != null){
jfc.setCurrentDirectory(lastBrowsed);
}
jfc.setMultiSelectionEnabled(false);
jfc.setFileSelectionMode( JFileChooser.FILES_ONLY );
int iRt = jfc.showOpenDialog(panel);
if ( iRt == JFileChooser.APPROVE_OPTION ) {
file = jfc.getSelectedFile();
file = FileUtil.normalizeFile(file);
}
File currDir = jfc.getCurrentDirectory();
if (currDir != null){
setLastBrowsedDir(type, currDir);
}
if (file != null){
String absPath = file.getAbsolutePath();
ret = FileSysUtil.Absolute2RelativePathStr(projDir,
file.getAbsoluteFile());
if (ret == null){
//This can happen in Windows where Project and Files are in
// different drives.
ret = absPath;
}
}
return ret;
}
示例7: selectNonExistingFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static String selectNonExistingFile(Component parent,String extensionWanted){
String forReturn = null;
final String endWith = extensionWanted;
JFileChooser chooser = new JFileChooser(lastChooserPath);
chooser.setFileFilter(new FileFilter(){
@Override
public boolean accept(File file) {
String filename = file.getName();
return (filename.endsWith(endWith)||file.isDirectory());
}
@Override
public String getDescription() {
return endWith;
}
});
int result = chooser.showSaveDialog(parent);
if ( result == JFileChooser.APPROVE_OPTION){
try{
lastChooserPath = chooser.getCurrentDirectory();
forReturn = chooser.getSelectedFile().getCanonicalPath();
}catch(Exception e){e.printStackTrace();}
}
if(forReturn != null){
if(!forReturn.endsWith(extensionWanted)){
forReturn += extensionWanted;
}
}
return forReturn;
}
示例8: initInteractiveCxfNetwork
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private InteractiveCxfNetwork initInteractiveCxfNetwork()
throws FileNotFoundException {
InteractiveCxfNetwork interactiveCxfNetwork = null;
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.gui.Cuttlefish.currentDirectory = fc
.getCurrentDirectory();
System.out
.println("Current directory: " + fc.getCurrentDirectory());
networkFile = fc.getSelectedFile();
interactiveCxfNetwork = new InteractiveCxfNetwork();
interactiveCxfNetwork.load(networkFile);
interactiveCxfNetwork.setNetworkLoaded(true);
} else {
System.out.println("Input cancelled by user");
return null;
}
fc = new FileChooser();
fc.setDialogTitle("Select a CEF file");
fc.setFileFilter(new FileNameExtensionFilter(".cef files", "cef"));
returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
networkFile = fc.getSelectedFile();
interactiveCxfNetwork.loadInstructions(networkFile);
} else {
System.out.println("Input cancelled by user");
}
return interactiveCxfNetwork;
}
示例9: selectFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static String selectFile(Component component, String name, String extension, File pathToUse){
JFileChooser chooser = new JFileChooser();
if(extension != null){
chooser.setFileFilter(new ExtensionFilter(extension));
}
boolean useGivenPath = pathToUse != null;
if (useGivenPath && lastIndicatedPath == null){
lastIndicatedPath = pathToUse;
}
chooser.setCurrentDirectory(useGivenPath?lastIndicatedPath:lastChooserPath);
int result = chooser.showDialog(component, name);
if ( result == JFileChooser.APPROVE_OPTION){
try{
if(useGivenPath){
lastIndicatedPath = chooser.getCurrentDirectory();
}else{
lastChooserPath = chooser.getCurrentDirectory();
}
String p = chooser.getSelectedFile().getAbsolutePath();
if (extension.startsWith(".")){
if (p.endsWith(extension)){
return p;
}else{
return p + extension;
}
}else{
if (p.endsWith(extension)){
return p;
}else{
return p + "." + extension;
}
}
}catch(Exception e){e.printStackTrace();}
}
return null;
}
示例10: 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();
}
示例11: doFileSelectionModeChanged
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void doFileSelectionModeChanged(PropertyChangeEvent e) {
doFilterChanged(e);
JFileChooser fc = getFileChooser();
File currentDirectory = fc.getCurrentDirectory();
if (currentDirectory != null && fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()
&& fc.getFileSystemView().isFileSystem(currentDirectory)) {
setFileName(currentDirectory.getPath());
} else {
setFileName(null);
}
setFileSelected();
}
示例12: _saveAs
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/** Query the user for a filename and save the plot to that file.
*/
protected void _saveAs() {
JFileChooser fileDialog = new JFileChooser();
fileDialog.addChoosableFileFilter(new PLTOrXMLFileFilter());
fileDialog.setDialogTitle("Save plot as...");
if (_directory != null) {
fileDialog.setCurrentDirectory(_directory);
} else {
// The default on Windows is to open at user.home, which is
// typically an absurd directory inside the O/S installation.
// So we use the current directory instead.
String cwd = StringUtilities.getProperty("user.dir");
if (cwd != null) {
fileDialog.setCurrentDirectory(new File(cwd));
}
}
fileDialog.setSelectedFile(new File(fileDialog.getCurrentDirectory(),
"plot.xml"));
int returnVal = fileDialog.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
_file = fileDialog.getSelectedFile();
setTitle(_file.getName());
_directory = fileDialog.getCurrentDirectory();
_save();
}
}
示例13: save
import javax.swing.JFileChooser; //导入方法依赖的package包/类
void save() {
if( pi==null||pi.getImage()==null )return;
JFileChooser chooser = haxby.map.MapApp.getFileChooser();
String name = "3Dimage.jpg";
File dir = chooser.getCurrentDirectory();
chooser.setSelectedFile(new File(dir,name));
File file = null;
while( true ) {
int ok = chooser.showSaveDialog(pi);
if( ok==chooser.CANCEL_OPTION)return;
file = chooser.getSelectedFile();
if( file.exists() ) {
ok=JOptionPane.showConfirmDialog(
pi,
"File exists, overwrite?");
if( ok==JOptionPane.CANCEL_OPTION)return;
if( ok==JOptionPane.YES_OPTION)break;
} else {
break;
}
}
try {
int sIndex = file.getName().lastIndexOf(".");
String suffix = sIndex<0
? "jpg"
: file.getName().substring( sIndex+1 );
if( !ImageIO.getImageWritersBySuffix(suffix).hasNext())suffix = "jpg";
ImageIO.write( pi.getImage(), suffix, file);
} catch(Exception ex) {
}
}
示例14: 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);
} else {
System.out.println("Input cancelled by user");
}
}
示例15: saveSaveDialogDir
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void saveSaveDialogDir(JFileChooser fc) {
try {
File currentDir = fc.getCurrentDirectory();
if (currentDir != null && currentDir.exists() && currentDir.isDirectory()) {
luytenPrefs.setFileSaveCurrentDirectory(currentDir.getAbsolutePath());
}
} catch (Exception e) {
Luyten.showExceptionDialog("Exception!", e);
}
}