Java Code Examples for javax.swing.JFileChooser#setFileHidingEnabled()

The following examples show how to use javax.swing.JFileChooser#setFileHidingEnabled() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: SettingsPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void btnDirectoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDirectoryActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Select alternate directory");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    String path = txtDirectory.getText();
    if (path == null || path.trim().length() == 0) {
        path = new File(System.getProperty("user.home")).getAbsolutePath(); //NOI18N
    }
    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();
        txtDirectory.setText(projectDir.getAbsolutePath());
    }

}
 
Example 2
Source Project: netbeans   File: SettingsPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Messages("TIT_GradleUserHome=Select Gradle User Home")
private void btGradleUserHomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btGradleUserHomeActionPerformed
    final GradleSettings settings = GradleSettings.getDefault();
    settings.getGradleUserHome();

    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(Bundle.TIT_GradleUserHome());
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    String path = tfGradleUserHome.getText();

    if (path.length() > 0) {
        File f = new File(path);
        if (f.exists()) {
            chooser.setSelectedFile(f);
        }
    }
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File home = chooser.getSelectedFile();
        tfGradleUserHome.setText(home.getAbsolutePath());
        gdm = GradleDistributionManager.get(home);
        cbGradleVersion.repaint();
    }
}
 
Example 3
Source Project: netbeans   File: RemoteRepository.java    License: Apache License 2.0 6 votes vote down vote up
private void onBrowse() {
    String path = settingsPanel.txtIdentityFile.getText();
    if (path.isEmpty()) {
        path = getDefaultIdentityFilePath();
    }
    File file = new File(path);
    JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(RemoteRepositoryPanel.class, "RepositoryPanel.IdentityFile.FileChooser.Descritpion"), //NOI18N
            path.isEmpty() ? null : file.getParentFile());
    if (!path.isEmpty()) {
        fileChooser.setSelectedFile(file);
    }
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setDialogTitle(NbBundle.getMessage(RemoteRepositoryPanel.class, "RepositoryPanel.IdentityFile.FileChooser.Title")); //NOI18N
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    if (JFileChooser.APPROVE_OPTION == fileChooser.showDialog(panel, null)) {
        File f = fileChooser.getSelectedFile();
        settingsPanel.txtIdentityFile.setText(f.getAbsolutePath());
    }
}
 
Example 4
Source Project: netbeans   File: SSHKeysPanel.java    License: Apache License 2.0 6 votes vote down vote up
private File openFile() {
    String home = System.getProperty("user.home"); // NOI18N
    JFileChooser chooser = new JFileChooser(home);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileHidingEnabled(false);
    int dlgResult = chooser.showOpenDialog(this);
    if (JFileChooser.APPROVE_OPTION == dlgResult) {
        File result = chooser.getSelectedFile();
        if (result != null && !result.exists()) {
            result = null;
        }
        return result;
    } else {
        return null;
    }
}
 
Example 5
Source Project: freecol   File: SaveDialog.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a dialog to choose a file to load.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param directory The directory to display when choosing the file.
 * @param fileFilters The available file filters in the dialog.
 * @param defaultName Name of the default save game file.
 */
public SaveDialog(FreeColClient freeColClient, JFrame frame,
        File directory, FileFilter[] fileFilters, String defaultName) {
    super(freeColClient, frame);

    final JFileChooser fileChooser = new JFileChooser(directory);
    if (fileFilters.length > 0) {
        for (FileFilter fileFilter : fileFilters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
        fileChooser.setFileFilter(fileFilters[0]);
        fileChooser.setAcceptAllFileFilterUsed(false);
    }
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    fileChooser.setSelectedFile(new File(defaultName));
    fileChooser.addActionListener((ActionEvent ae) ->
            setValue((JFileChooser.APPROVE_SELECTION
                    .equals(ae.getActionCommand()))
                ? fileChooser.getSelectedFile() : cancelFile));
    
    List<ChoiceItem<File>> c = choices();
    initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
 
Example 6
@SuppressForbidden(reason = "FileChooser#getSelectedFile() returns java.io.File")
void browseDirectory(ActionEvent e) {
  File currentDir = getLastOpenedDirectory();
  JFileChooser fc = currentDir == null ? new JFileChooser() : new JFileChooser(currentDir);
  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fc.setFileHidingEnabled(false);
  int retVal = fc.showOpenDialog(dialog);
  if (retVal == JFileChooser.APPROVE_OPTION) {
    File dir = fc.getSelectedFile();
    idxPathCombo.insertItemAt(dir.getAbsolutePath(), 0);
    idxPathCombo.setSelectedIndex(0);
  }
}
 
Example 7
@CalledOnlyBy(AmidstThread.EDT)
private JFileChooser createSaveGameFileChooser() {
	JFileChooser result = new JFileChooser(runningLauncherProfile.getLauncherProfile().getSaves().toFile());
	result.setFileFilter(new LevelFileFilter());
	result.setAcceptAllFileFilterUsed(false);
	result.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
	result.setFileHidingEnabled(false);
	return result;
}
 
Example 8
Source Project: netbeans   File: MavenGroupPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void browseAddNewRuntime() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(SettingsPanel.class, "TIT_Select2"));
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    int selected = comMavenHome.getSelectedIndex();
    String path = getSelectedRuntime(selected);
    if (path == null || path.trim().length() == 0) {
        path = new File(System.getProperty("user.home")).getAbsolutePath(); //NOI18N
    }
    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();
        String newRuntimePath = FileUtil.normalizeFile(projectDir).getAbsolutePath();
        boolean existed = false;
        List<String> runtimes = new ArrayList<String>();
        runtimes.addAll(predefinedRuntimes);
        runtimes.addAll(userDefinedMavenRuntimes);
        for (String runtime : runtimes) {
            if (runtime.equals(newRuntimePath)) {
                existed = true;
            }
        }
        if (!existed) {
            // do not add duplicated directory
            if (userDefinedMavenRuntimes.isEmpty()) {
                mavenHomeDataModel.insertElementAt(SEPARATOR, predefinedRuntimes.size());
            }
            userDefinedMavenRuntimes.add(newRuntimePath);
            mavenHomeDataModel.insertElementAt(newRuntimePath, runtimes.size() + 1);
        }
        comMavenHome.setSelectedItem(newRuntimePath);
    }
}
 
Example 9
public void rtC()
{
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileFilter()
    {
        @Override
        public boolean accept(File f)
        {
            return true;
        }

        @Override
        public String getDescription()
        {
            return "JRE RT Library";
        }
    });
    fc.setFileHidingEnabled(false);
    fc.setAcceptAllFileFilterUsed(false);
    int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);

    if (returnVal == JFileChooser.APPROVE_OPTION)
        try
        {
            BytecodeViewer.rt = fc.getSelectedFile().getAbsolutePath();
        }
        catch (Exception e1)
        {
            new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
        }
}
 
Example 10
public void pythonC()
{
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileFilter()
    {
        @Override
        public boolean accept(File f)
        {
            return true;
        }

        @Override
        public String getDescription()
        {
            return "Python (Or PyPy for speed) 2.7 Executable";
        }
    });
    fc.setFileHidingEnabled(false);
    fc.setAcceptAllFileFilterUsed(false);
    int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);

    if (returnVal == JFileChooser.APPROVE_OPTION)
        try
        {
            BytecodeViewer.python = fc.getSelectedFile().getAbsolutePath();
        }
        catch (Exception e1)
        {
            new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
        }
}
 
Example 11
public void library()
{
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileFilter()
    {
        @Override
        public boolean accept(File f)
        {
            return f.isDirectory();
        }

        @Override
        public String getDescription()
        {
            return "Optional Library Folder";
        }
    });
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setFileHidingEnabled(false);
    fc.setAcceptAllFileFilterUsed(false);
    int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);

    if (returnVal == JFileChooser.APPROVE_OPTION)
        try
        {
            BytecodeViewer.library = fc.getSelectedFile().getAbsolutePath();
        }
        catch (Exception e1)
        {
            new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
        }
}
 
Example 12
public void java()
{
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileFilter()
    {
        @Override
        public boolean accept(File f)
        {
            return true;
        }

        @Override
        public String getDescription()
        {
            return "Java Executable (Inside Of JRE/JDK 'C:/programfiles/Java/JDK_xx/bin/java.exe')";
        }
    });
    fc.setFileHidingEnabled(false);
    fc.setAcceptAllFileFilterUsed(false);
    int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);

    if (returnVal == JFileChooser.APPROVE_OPTION)
        try
        {
            BytecodeViewer.java = fc.getSelectedFile().getAbsolutePath();
        }
        catch (Exception e1)
        {
            new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
        }
}
 
Example 13
Source Project: netbeans   File: ConfigurationPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    String text = UiUtils.getValue(certTextField);
    if (text != null) {
        chooser.setSelectedFile(new File(text));
    }
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        certTextField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 14
private void certBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_certBrowseButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    String text = UiUtils.getValue(certTextField);
    if (text != null) {
        chooser.setSelectedFile(new File(text));
    }
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        certTextField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 15
@CalledOnlyBy(AmidstThread.EDT)
private JFileChooser createSaveGameFileChooser() {
	JFileChooser result = new JFileChooser(runningLauncherProfile.getLauncherProfile().getSaves().toFile());
	result.setFileFilter(new LevelFileFilter());
	result.setAcceptAllFileFilterUsed(false);
	result.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
	result.setFileHidingEnabled(false);
	return result;
}
 
Example 16
Source Project: netbeans   File: VariablePanel.java    License: Apache License 2.0 5 votes vote down vote up
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileHidingEnabled(false);
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setDialogTitle(NbBundle.getBundle(VariablePanel.class).getString("MSG_Choose_Folder"));
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        locationTextField.setText(file.getAbsolutePath());
    }
}
 
Example 17
public void pythonC3()
{
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileFilter()
    {
        @Override
        public boolean accept(File f)
        {
            return true;
        }

        @Override
        public String getDescription()
        {
            return "Python (Or PyPy for speed) 3.x Executable";
        }
    });
    fc.setFileHidingEnabled(false);
    fc.setAcceptAllFileFilterUsed(false);
    int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);

    if (returnVal == JFileChooser.APPROVE_OPTION)
        try
        {
            BytecodeViewer.python3 = fc.getSelectedFile().getAbsolutePath();
        }
        catch (Exception e1)
        {
            new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e1);
        }
}
 
Example 18
public static File showSaveFileDialog( final Component parent, final String title, final File initialPath ) {
    RunnableWithParameters runnable = new RunnableWithParameters(){
        public void run() {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle(title);
            fc.setDialogType(JFileChooser.SAVE_DIALOG);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fc.setCurrentDirectory(initialPath);
            fc.setFileHidingEnabled(false);
            int r = fc.showOpenDialog(parent);
            if (r != JFileChooser.APPROVE_OPTION) {
                this.returnValue = null;
                return;
            }

            File selectedFile = fc.getSelectedFile();
            if (selectedFile != null && selectedFile.getParentFile().exists())
                PreferencesHandler.setLastPath(selectedFile.getParentFile().getAbsolutePath());
            this.returnValue = selectedFile;

        }
    };
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (Exception e) {
            Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e);
        }
    }
    return (File) runnable.getReturnValue();
}
 
Example 19
@SuppressForbidden(reason = "JFilechooser#getSelectedFile() returns java.io.File")
private void browseDirectory(JTextField tf) {
  JFileChooser fc = new JFileChooser(new File(tf.getText()));
  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fc.setFileHidingEnabled(false);
  int retVal = fc.showOpenDialog(dialog);
  if (retVal == JFileChooser.APPROVE_OPTION) {
    File dir = fc.getSelectedFile();
    tf.setText(dir.getAbsolutePath());
  }
}
 
Example 20
public static File[] showOpenFilesDialog( final Component parent, final String title, final boolean multiselection,
        final File initialPath, final FileFilter filter ) {
    RunnableWithParameters runnable = new RunnableWithParameters(){
        public void run() {
            JFileChooser fc = new JFileChooser();
            fc.setDialogTitle(title);
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fc.setMultiSelectionEnabled(multiselection);
            fc.setCurrentDirectory(initialPath);
            if (filter != null)
                fc.setFileFilter(filter);
            fc.setFileHidingEnabled(false);
            int r = fc.showOpenDialog(parent);
            if (r != JFileChooser.APPROVE_OPTION) {
                this.returnValue = null;
                return;
            }

            if (fc.isMultiSelectionEnabled()) {
                File[] selectedFiles = fc.getSelectedFiles();
                this.returnValue = selectedFiles;
            } else {
                File selectedFile = fc.getSelectedFile();
                if (selectedFile != null && selectedFile.exists())
                    PreferencesHandler.setLastPath(selectedFile.getAbsolutePath());
                this.returnValue = new File[]{selectedFile};
            }

        }
    };
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (Exception e) {
            Logger.INSTANCE.insertError("", "Can't show chooser dialog '" + title + "'.", e);
        }
    }
    return (File[]) runnable.getReturnValue();
}