Close

Java 12 - Getting JFileChooser shortcuts panel's files with FileSystemView# getChooserShortcutPanelFiles()

[Updated: Apr 4, 2019, Created: Apr 3, 2019]

Java 12 added following method in javax.swing.filechooser.FileSystemView:

public File[] getChooserShortcutPanelFiles()

This method returns an array of files representing the values shown by default in the file chooser shortcuts panel.

Example

package com.logicbig.example;

import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
import java.io.File;

public class ShortcutPanelFilesExample {
  public static void main(String[] args) throws Exception {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      JFileChooser chooser = new JFileChooser();
      FileSystemView view = chooser.getFileSystemView();
      System.out.println("The shortcut panel files: ");
      File[] chooserShortcutPanelFiles = view.getChooserShortcutPanelFiles();
      for (File chooserShortcutPanelFile : chooserShortcutPanelFiles) {
          System.out.println(chooserShortcutPanelFile);
      }
      chooser.showOpenDialog(null);
  }
}

Output

The shortcut panel files: 
C:\Users\joe\AppData\Roaming\Microsoft\Windows\Recent
C:\Users\joe\Desktop
C:\Users\joe\Documents
This PC
Network

Also checkout the reason this method was added.

Example Project

Dependencies and Technologies Used:

  • JDK 12
Java 12 Swing's new FileSystemView method Example Select All Download
  • java-12-file-system-view-changes
    • src
      • com
        • logicbig
          • example
            • ShortcutPanelFilesExample.java

    See Also