Check if hidden files are displayed in the FileChooser or not in Java


The result FALSE for is FileHidingEnabled() means the hidden files are displayed in the FileChooser. 

The following will display FALSE since file isn’t hidden −

JFileChooser file = new JFileChooser();
file.setMultiSelectionEnabled(false);
file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
file.setFileHidingEnabled(false);
boolean res = file.isFileHidingEnabled();

Above, at first, we have displayed the file by setting hidden to be FALSE −

file.setFileHidingEnabled(false);

The following is an example −

Example

package my;
import javax.swing.JFileChooser;
public class SwingDemo {
   public static void main(String[] args) {
      JFileChooser file = new JFileChooser();
      file.setMultiSelectionEnabled(false);
      file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
      file.setFileHidingEnabled(false);
      boolean res = file.isFileHidingEnabled();
      System.out.println("File are hidden in the FileChooser? "+res);
   }
}

Output

Updated on: 30-Jul-2019

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements