JavaFX Filesystem Viewers

JavaFX 8 has 2 controls (=dialogs) to browse the filesystem

  • javafx.stage.DirectoryChooser native_dir
  • javafx.stage.FileChooser native_file

who create native resource dialogs but if you want to integrate a directory view in your application and/or you want custom features like a file preview those dialogs are of no help.

I had just this use case and so I implemented 3 different controls:

  • org.eclipse.fx.ui.controls.filesystem.DirectoryTreeView: Display a directory structure as a tree
  • org.eclipse.fx.ui.controls.filesystem.DirectoryView: Display the contents of a directory – currently only a list view is available
  • org.eclipse.fx.ui.controls.filesystem.ResourcePreview: Display preview informations of a file e.g. a thumb for images

If you combine them you get a nice file browser you can integration just anywhere


Usage is straight forward:

package org.eclipse.fx.ui.controls.sample;

import java.nio.file.Paths;

import javafx.application.Application;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.stage.Stage;

import org.eclipse.fx.ui.controls.filesystem.DirectoryTreeView;
import org.eclipse.fx.ui.controls.filesystem.DirectoryView;
import org.eclipse.fx.ui.controls.filesystem.IconSize;
import org.eclipse.fx.ui.controls.filesystem.ResourceItem;
import org.eclipse.fx.ui.controls.filesystem.ResourcePreview;
import org.eclipse.fx.ui.controls.filesystem.RootDirItem;

public class DirectoryViewSample extends Application {

  private static RootDirItem rootDirItem;

  public void start(Stage primaryStage) throws Exception {
    rootDirItem = ResourceItem.createObservedPath(

    DirectoryTreeView tv = new DirectoryTreeView();

    DirectoryView v = new DirectoryView();

    tv.getSelectedItems().addListener( (Observable o) -> {
      if( ! tv.getSelectedItems().isEmpty() ) {
      } else {

    ResourcePreview prev = new ResourcePreview();
    v.getSelectedItems().addListener((Observable o) -> {
      if( v.getSelectedItems().size() == 1 ) {
      } else {

    SplitPane p = new SplitPane(tv,v, prev);

    Scene s = new Scene(p,500,500);

  public static void main(String[] args) {

12 thoughts on “JavaFX Filesystem Viewers

  1. Journeyman GM January 13, 2015 / 6:15 pm

    As a user, I would much prefer the native file dialog to this version. The original native dialog that you show has a list of common folders on the left side (e.g. Downloads, Documents), different views (including Column View which already includes a preview thumbnail), tags, and a search bar. All of those are lacking in the new dialog. Moreover, it just looks odd and is likely to confuse end users who would be much more comfortable with a native dialog.A

    While I suppose it’s good to know all of the options that are available, I think that it would be better to just stick with the native dialog in any apps.

    • Tom Schindl January 13, 2015 / 9:37 pm

      I can see your point but maybe I was not clear enough the viewer and the dialogs solve very different problems and there’s always a need to browse a file system inside applications whereas I’d also use the native dialogs e.g. to open files.

  2. George Moralis January 20, 2015 / 9:05 pm

    nice work! will that be open source?

    • Tom Schindl January 20, 2015 / 9:06 pm

      Yes sources are under EPL and available from the efxclipse git-repo

  3. mohsin January 25, 2015 / 1:04 pm

    how to use this tutorial in Netbeans JavaFx

    • Tom Schindl January 25, 2015 / 1:29 pm

      Not sure what you mean – there is no tutorial – this is just a library

      • mohsin January 25, 2015 / 1:35 pm

        I also want to integrate file explorer in my application and i am using Netbeans. I only find this resource useful. So I am actually asking how can i use this type of code in JAVAFX using netbeans

  4. mohsin January 26, 2015 / 12:56 pm

    Thank you very much !

  5. Laskawiec October 11, 2015 / 4:25 pm

    Interesting job but I have NPE when I select some folder which contains hidden folder (like AppData for example):
    Exception in thread “JavaFX Application Thread” java.lang.NullPointerException
    at$$Lambda$288/1139353194.apply(Unknown Source)
    at org.eclipse.fx.ui.controls.tree.SimpleTreeCell.updateItem(

    • Tom Schindl October 11, 2015 / 5:09 pm

      File a bug report

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s