本文整理汇总了Java中javax.swing.JFileChooser.setFileSelectionMode方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.setFileSelectionMode方法的具体用法?Java JFileChooser.setFileSelectionMode怎么用?Java JFileChooser.setFileSelectionMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.setFileSelectionMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: export
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Export the report.
*/
private void export() {
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (JFileChooser.APPROVE_OPTION == fc.showOpenDialog(this)) {
final File file = new File(fc.getSelectedFile(), "report.csv");
try {
Files.write(
Paths.get(file.getAbsolutePath()),
new CsvReport(this.marking.submissions())
.report(true)
.getBytes()
);
} catch (IOException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(
this, e1.getMessage(), "Export error", JOptionPane.ERROR_MESSAGE);
}
}
}
示例2: buildContextButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void buildContextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buildContextButtonActionPerformed
FileChooserBuilder builder = FileChooserBuilder.create(fileSystem);
JFileChooser fileChooser = builder.createFileChooser();
fileChooser.setApproveButtonText(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.button")); // NOI18M
fileChooser.setDialogTitle(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.dialogTitle")); // NOI18M
fileChooser.setFileSelectionMode(0);
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
String buildText = UiUtils.getValue(buildContextTextField);
if (buildText != null) {
fileChooser.setSelectedFile(new File(buildText));
}
if (fileChooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
buildContextTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
}
}
示例3: browseAntScriptActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void browseAntScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseAntScriptActionPerformed
JFileChooser chooser = new JFileChooser();
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
if (antScript.getText().length() > 0 && getAntScript().exists()) {
chooser.setSelectedFile(getAntScript());
} else if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
chooser.setSelectedFile(getProjectLocation());
} else {
chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
}
chooser.setDialogTitle(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_Browse_Build_Script")); //NOI18N
if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
File script = FileUtil.normalizeFile(chooser.getSelectedFile());
antScript.setText(script.getAbsolutePath());
}
}
示例4: btnWorkDirActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void btnWorkDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWorkDirActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(null);
chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
chooser.setMultiSelectionEnabled(false);
String workDir = txtWorkDir.getText();
if (workDir.equals("")) { //NOI18N
workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
}
chooser.setSelectedFile(new File(workDir));
chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(RunJarPanel.class, "TIT_SelectWorkingDirectory"));
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
File file = FileUtil.normalizeFile(chooser.getSelectedFile());
txtWorkDir.setText(file.getAbsolutePath());
}
}
示例5: browseButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
String command = evt.getActionCommand();
if ("BROWSE".equals(command)) {
JFileChooser chooser = new JFileChooser();
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setDialogTitle("Select Project Location");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
String path = this.projectLocationTextField.getText();
if (path.length() > 0) {
File f = new File(path);
if (f.exists()) {
chooser.setSelectedFile(f);
}
}
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
File projectDir = chooser.getSelectedFile();
projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath());
}
panel.fireChangeEvent();
}
}
示例6: selectDirectory
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static String selectDirectory(Component component, String choosertitle)
{
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(component) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
return chooser.getSelectedFile().toString();
}
else {
System.out.println("No Selection ");
return null;
}
}
示例7: splashButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void splashButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_splashButtonActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(null);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(false);
chooser.setFileFilter(new IconFileFilter(false));
String current = splashTextField.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));
splashTextField.setText(relPath);
lastImageFolder = file;
}
}
示例8: open
import javax.swing.JFileChooser; //导入方法依赖的package包/类
void open() throws IOException {
JFileChooser chooser = haxby.map.MapApp.getFileChooser();
int mode = chooser.getFileSelectionMode();
boolean multi = chooser.isMultiSelectionEnabled();
chooser.setMultiSelectionEnabled( true );
chooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
chooser.addChoosableFileFilter(imageFileFilter);
int ok = chooser.showOpenDialog(frame);
File[] choice = null;
if( ok!=chooser.CANCEL_OPTION ) choice = chooser.getSelectedFiles();
chooser.setMultiSelectionEnabled(multi);
chooser.setFileSelectionMode( mode );
chooser.removeChoosableFileFilter(imageFileFilter);
if( ok==chooser.CANCEL_OPTION ) {
return;
}
if (mapType == MapApp.MERCATOR_MAP)
openImagesMercator(choice);
else
openImagesPolar(choice);
}
示例9: 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();
}
}
示例10: fileChooser
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void fileChooser(){
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File(jpreferAnon.get("csvLocation", System.getProperty("user.dir"))));
chooser.setDialogTitle("Export csv to...");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
this.path = chooser.getSelectedFile().toPath();
jpreferAnon.put("csvLocation", this.path.toString());
this.choix[0] = true;
} else {
this.choix[0] = false;
}
}
示例11: getChosenExportFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public File getChosenExportFile(){
//! eigene Methode und nicht alte weiterverwenden deswegen, weilst
//! das mit dem 'Ordner auswählen' wolltest...
//! dann iss allerdings blöd mit filenamen festlegen, ich vermute,
//! der gibt dir den path zum ordner zrück. aber vllt sinds eh fixe
//! namen dann passts ja, stells halt OBEN um
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // user can only select directories
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
return fc.getSelectedFile();
else
return null;
}
示例12: 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();
}
}
示例13: selectAppBrowseB_actionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
void selectAppBrowseB_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.setDialogTitle(Local.getString("Path to executable"));
chooser.setFileHidingEnabled(false);
chooser.setAcceptAllFileFilterUsed(true);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (System.getProperty("os.name").startsWith("Win")) {
chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.EXE));
chooser.setCurrentDirectory(new File("C:\\Program Files"));
}
chooser.setPreferredSize(new Dimension(550, 375));
/*
java.io.File lastSel = (java.io.File) Context.get("LAST_SELECTED_IMPORT_FILE");
if (lastSel != null)
chooser.setCurrentDirectory(lastSel);
*/
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
applicationField.setText(chooser.getSelectedFile().getPath());
}
示例14: chooseSubPathBtnActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void chooseSubPathBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseSubPathBtnActionPerformed
// TODO add your handling code here:
JFileChooser f = new JFileChooser();
f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
f.showOpenDialog(this);
subPathToSend = f.getSelectedFile();
subPathField.setText(subPathToSend.getAbsolutePath());
}
示例15: 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());
}
}