本文整理汇总了Java中javax.swing.JFileChooser.showDialog方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.showDialog方法的具体用法?Java JFileChooser.showDialog怎么用?Java JFileChooser.showDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.showDialog方法的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: selectDirectory
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static String selectDirectory(Component component,String name,File pathToUse){
JFileChooser chooser = new JFileChooser();
boolean useIndicated = pathToUse != null;
if (useIndicated && lastIndicatedPath == null){
lastIndicatedPath = pathToUse;
}
chooser.setCurrentDirectory(useIndicated?lastIndicatedPath:lastChooserPath);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result = chooser.showDialog(component, name);
if ( result == JFileChooser.APPROVE_OPTION){
try{
if(useIndicated){
lastIndicatedPath = chooser.getCurrentDirectory();
}else{
lastChooserPath = chooser.getCurrentDirectory();
}
return chooser.getSelectedFile().getAbsolutePath();
}catch(Exception e){e.printStackTrace();}
}
return null;
}
示例3: btnFileActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Messages({"TIT_Choose=Choose Directory To Check Out", "LBL_Select=Select"})
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
JFileChooser chooser = new JFileChooser(lastFolder);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogTitle(TIT_Choose());
chooser.setMultiSelectionEnabled(false);
if (txtFolder.getText().trim().length() > 0) {
File fil = new File(txtFolder.getText().trim());
if (fil.exists()) {
chooser.setSelectedFile(fil);
}
}
int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), LBL_Select());
if (ret == JFileChooser.APPROVE_OPTION) {
txtFolder.setText(chooser.getSelectedFile().getAbsolutePath());
txtFolder.requestFocusInWindow();
}
}
示例4: 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());
}
}
示例5: 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;
}
示例6: browseLicenceButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void browseLicenceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLicenceButtonActionPerformed
JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastChosenLibraryLocation());
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(false);
if (txtLicense.getText().trim().length() > 0) {
chooser.setSelectedFile(new File(txtLicense.getText().trim()));
}
int ret = chooser.showDialog(this, getMessage("LBL_Select"));
if (ret == JFileChooser.APPROVE_OPTION) {
txtLicense.setText(chooser.getSelectedFile().getAbsolutePath());
ModuleUISettings.getDefault().setLastChosenLibraryLocation(txtLicense.getText());
}
}
示例7: btnFileActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
// TODO add your handling code here:
JFileChooser chooser = new JFileChooser(lastFolder);
chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(InstallPanel.class, "TIT_Select_Artifact"));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return (f.isDirectory() || f.getName().toLowerCase().endsWith(".jar"));//NOI18N
}
@Override
public String getDescription() {
return org.openide.util.NbBundle.getMessage(InstallPanel.class, "SEL_Jars");
}
});
chooser.setMultiSelectionEnabled(false);
if (txtFile.getText().trim().length() > 0) {
File fil = new File(txtFile.getText().trim());
if (fil.exists()) {
chooser.setSelectedFile(fil);
}
}
int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), org.openide.util.NbBundle.getMessage(InstallPanel.class, "TIT_Select"));
if (ret == JFileChooser.APPROVE_OPTION) {
txtFile.setText(chooser.getSelectedFile().getAbsolutePath());
txtFile.requestFocusInWindow();
}
}
示例8: btnFileActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
JFileChooser chooser = new JFileChooser(lastFolder);
chooser.setDialogTitle(isJavadoc() ? NbBundle.getMessage(InstallDocSourcePanel.class, "TIT_Select_javadoc_zip")
: NbBundle.getMessage(InstallDocSourcePanel.class, "TIT_Select_source_zip"));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return (f.isDirectory() || f.getName().toLowerCase().endsWith(".jar") || f.getName().toLowerCase().endsWith(".zip")); //NOI18N
}
@Override
public String getDescription() {
return isJavadoc() ? NbBundle.getMessage(InstallDocSourcePanel.class, "LBL_Select_javadoc_zip")
: NbBundle.getMessage(InstallDocSourcePanel.class, "LBL_Select_source_zip");
}
});
chooser.setMultiSelectionEnabled(false);
if (txtFile.getText().trim().length() > 0) {
File fil = new File(txtFile.getText().trim());
if (fil.exists()) {
chooser.setSelectedFile(fil);
}
}
int ret = chooser.showDialog(SwingUtilities.getWindowAncestor(this), BTN_Select());
if (ret == JFileChooser.APPROVE_OPTION) {
txtFile.setText(chooser.getSelectedFile().getAbsolutePath());
txtFile.requestFocusInWindow();
}
}
示例9: onBrowse
import javax.swing.JFileChooser; //导入方法依赖的package包/类
protected void onBrowse(JTextField txt) {
File oldFile = FileUtil.normalizeFile(new File(txt.getText()));
JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(Repository.class, "ACSD_BrowseCertFile"), oldFile); // NOI18N
fileChooser.setDialogTitle(NbBundle.getMessage(Repository.class, "Browse_title")); // NOI18N
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.showDialog(this.getPanel(), NbBundle.getMessage(Repository.class, "OK_Button")); // NOI18N
File f = fileChooser.getSelectedFile();
if (f != null) {
txt.setText(f.getAbsolutePath());
}
}
示例10: browseActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Messages("LBL_Select=Select")
private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
JFileChooser jfc = new JFileChooser();
jfc.setSelectedFile(new File(standard.getProjectLocation(), fileLocation.getText()));
if (jfc.showDialog(this, Bundle.LBL_Select()) == JFileChooser.APPROVE_OPTION) {
fileLocation.setText(standard.getProjectLocation().toURI().relativize(jfc.getSelectedFile().toURI()).getPath());
}
}
示例11: jButton3ActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
JFileChooser jfc = new JFileChooser ();
jfc.setFileSelectionMode(jfc.DIRECTORIES_ONLY);
jfc.showDialog(this, "Choose a directory with cache files");
File fi = jfc.getSelectedFile();
try {
if (fi==null || (!fi.exists() && !fi.isDirectory())) {
System.err.println("I can't do that: " + fi);
return;
}
CacheReader r = new CacheReader (fi);
String[] s = r.getIDs();
for (int i=0; i < s.length; i++) {
File f = new File(s[i]);
BufferedImage img = (BufferedImage) r.find(s[i]);
ImagePanel ip = new ImagePanel(img);
ip.setName ("c-" + s[i]);
jTabbedPane2.insertTab(f.getName(), null, new JScrollPane(ip), f.toString(), 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: onExecPathBrowseClick
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void onExecPathBrowseClick() {
File oldFile = getExportFile();
JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(MercurialOptionsPanelController.class, "ACSD_BrowseFolder"), oldFile); // NOI18N
fileChooser.setDialogTitle(NbBundle.getMessage(MercurialOptionsPanelController.class, "Browse_title")); // NOI18N
fileChooser.setMultiSelectionEnabled(false);
fileChooser.showDialog(panel, NbBundle.getMessage(MercurialOptionsPanelController.class, "OK_Button")); // NOI18N
File f = fileChooser.getSelectedFile();
if (f != null) {
panel.executablePathTextField.setText(f.getAbsolutePath());
}
}
示例13: addDirButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void addDirButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDirButtonActionPerformed
JFileChooser chooser = FileEditor.createHackedFileChooser();
chooser.setFileHidingEnabled(false);
setHelpToChooser( chooser );
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogTitle(getString("CTL_FileSystemPanel.Local_Dialog_Title"));
if (lastDirFolder != null) {
chooser.setCurrentDirectory(lastDirFolder);
}
if (chooser.showDialog(this,
getString("CTL_Approve_Button_Title"))
== JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
if ((f != null) && (f.isDirectory())) {
lastDirFolder = f.getParentFile();
String path = f.getAbsolutePath();
if (! listModel.contains (path)) {
listModel.addElement (path);
}
fireValueChanged();
pathList.setSelectedIndex(listModel.size() - 1);
}
}
}
示例14: btnIconActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void btnIconActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIconActionPerformed
JFileChooser chooser = WizardUtils.getIconFileChooser(txtIcon.getText());
int ret = chooser.showDialog(this, getMessage("LBL_Select")); // NOI18N
if (ret == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
txtIcon.setText(file.getAbsolutePath());
}
}
示例15: doSelectLoggingFolder
import javax.swing.JFileChooser; //导入方法依赖的package包/类
synchronized public void doSelectLoggingFolder() {
JFileChooser c = new JFileChooser(lastLoggingFolder);
c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int ret = c.showDialog(chip.getAeViewer().getFilterFrame(), "Select folder");
if (ret != JFileChooser.APPROVE_OPTION) {
return;
}
lastLoggingFolder = c.getSelectedFile().getPath();
putString("lastLoggingFolder", lastLoggingFolder);
tobiLogger = new TobiLogger(lastLoggingFolder + File.separator + "TimestampCalibrator", "SystemTimeMillis dtClockNs dtTsUs");
tobiLogger.setAbsoluteTimeEnabled(true);
tobiLogger.setEnabled(true);// creates log file
tobiLogger.addComment("timestamp calibrator log file");
}