... (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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.