Java Swing How to - Disable New Folder Button in JFileChooser








Question

We would like to know how to disable New Folder Button in JFileChooser.

Answer

import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.plaf.basic.BasicFileChooserUI;
// ww w  .  j  a  v a  2s.  c o  m
public class Main {
  public static void main(String[] args) {
    JFileChooser chooser = new JFileChooser();

    BasicFileChooserUI ui = (BasicFileChooserUI) chooser.getUI();
    Action folder = ui.getNewFolderAction();
    folder.setEnabled(false);

    chooser.showSaveDialog(null);
  }
}