... (file != null) {
39            analyzePath(file.toPath());
40         }
41         else {
42            textArea.setText("Select file or directory");
43         }
44      }
45
46      // handles selectDirectoryButton's events
47      @FXML
48      private void selectDirectoryButtonPressed(ActionEvent e) {
49         // configure dialog allowing selection of a directory
50         DirectoryChooser directoryChooser = new DirectoryChooser();
51         directoryChooser.setTitle("Select Directory");             
52
53         // display folder from which the app was launched
54         directoryChooser.setInitialDirectory(new File("."));
55
56         // display the FileChooser
57         File file = directoryChooser.showDialog(
58            borderPane.getScene().getWindow());  
59
60         // process selected Path or display a message
61         if (file != null) {
62            analyzePath(file.toPath());
63         }
64 ...

Get Java How To Program, Late Objects, 11th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.