1

Is it possible to display files available in the folder when using DirectoryChooser in JavaFX?

directoryChooser.showDialog - This the the dialog for DirectoryChosser in JavaFX.

This question is asked before & i have gone through this JavaFX - display files in the DirectoryChooser

I was able to achieve this using JFileChooser but the UI is completely different JFileChooser select directory but show files

JFileChooser code:

final JFileChooser chooser = new JFileChooser() {
        public void approveSelection() {
            if (getSelectedFile().isFile()) {
                return;
            } else{
                super.approveSelection();
                stubFolder.setText(getCurrentDirectory().getAbsolutePath());
            }
        }
    };
    chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES );
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
        System.out.println("getSelectedFile() : " + chooser.getSelectedFile());
    } else {
        System.out.println("No Selection ");
    }
aAv
  • 41
  • 4
  • 1
    `JFileChooser` is not in the `JavaFX` library. https://docs.oracle.com/javafx/2/ui_controls/file-chooser.htm – SedJ601 May 01 '18 at 06:37
  • That is correct JFileChooser is part of Swing - javax.swing.JFileChooser. It can be used in JavaFX to display files when selecting folder. But the UI is Swing based & does not match the native system UI. – aAv May 02 '18 at 01:19
  • I think I am just confused about why you showed the code for `Swing` components. Have you attempted to use the `JavaFX` version? – SedJ601 May 02 '18 at 01:25
  • You can use SwingNode (javafx.embed.swing.SwingNode) to embed Swing components in JavaFX. JFileChooser is one of the ways in JavaFX to display files when selecting folder. But the UI is swing based. As per my understanding, JavaFX does not have any way to display files when selecting folder using DirectoryChooser. And i want an answer if there is any way to do it. – aAv May 02 '18 at 03:46

0 Answers0