title: How to restrict file choosers in java to specific files?
body: <pre><code>private void openMenuActionPerformed(java.awt.event.ActionEvent evt) {
      
      DBmanager db = new DBmanager();
      if (!db.getCurrentUser().equals(&quot;Admin&quot;)) {
          JOptionPane.showMessageDialog(this, &quot;You are Not Allowed to Run Applications&quot;);
          JFileChooser fileChooser = new JFileChooser();
          fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
          fileChooser.addChoosableFileFilter(new FileNameExtensionFilter(&quot;PDF Documents&quot;, &quot;pdf&quot;));
          fileChooser.addChoosableFileFilter(new FileNameExtensionFilter(&quot;MS Office Documents&quot;, &quot;docx&quot;, &quot;xlsx&quot;, &quot;pptx&quot;));
          fileChooser.addChoosableFileFilter(new FileNameExtensionFilter(&quot;Images&quot;, &quot;jpg&quot;, &quot;png&quot;, &quot;gif&quot;, &quot;bmp&quot;));
          fileChooser.setAcceptAllFileFilterUsed(false);
          int returnVal = fileChooser.showOpenDialog(this);
  
          if (returnVal == JFileChooser.APPROVE_OPTION) {
              File file = fileChooser.getSelectedFile();
  
              if (Desktop.isDesktopSupported()) {
                  try {
                      Desktop.getDesktop().open(file);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
      } else if (db.getCurrentUser().equals(&quot;Admin&quot;)) {
          JFileChooser fileChooser = new JFileChooser();
          fileChooser.setAcceptAllFileFilterUsed(true);
          int returnVal = fileChooser.showOpenDialog(this);
          if (returnVal == JFileChooser.APPROVE_OPTION) {
              File file = fileChooser.getSelectedFile();
              if (Desktop.isDesktopSupported()) {
                  try {
                      Desktop.getDesktop().open(file);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
      }// TODO add your handling code here:
  }
  </code></pre>
  <p>I am trying to filter files in a file filter by setting <code>fileChooser.setAcceptAllFileFilterUsed(false);</code>. The &quot;all files&quot; option disappears from the <code>FileChooser</code> but all files remain visible unless you select an option from PDF documents,ms Office or images. I want to have only my 3 custom filters upon opening the file chooser.</p>