title: How to get properties of a selected file from a JFileChooser
body: <p>I have an FXML controller class with a textfield that I want populated with various file properties of a file a user selects via a FileChooser.</p>
  
  <p>The controller looks like:</p>
  
  <pre><code>@FXML
  TextField documentName;
  
  File file;
  
  public void attachNewDocFileChooser() {
      file = new MyFileChooser().chooser();
      if (file != null) {
          documentName.setText(file.getName());
      } else {
          documentName.setText("No file selected");
      }
  }
  </code></pre>
  
  <p>The FileChooser is created in a different class <code>MyFileChooser</code>:</p>
  
  <pre><code>@FXML
  public File chooser() {
      File file = null;
      final JFileChooser fileDialog = new JFileChooser();
  
      int returnVal = fileDialog.showOpenDialog(null);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
          file = fileDialog.getSelectedFile();
      }
      return file;
  }
  </code></pre>
  
  <p>I can't get the textfield <code>documentName</code> populated with the name of the file selected.</p>
  
  <p>I'll be very grateful for any help at making this work. Thank you all in advance.</p>
  
  <p>Update:
  I get a <code>java.lang.NullPointerException</code>.</p>
  
  <p>I also forgot to mention that <code>chooser()</code> is linked to a Label so that <code>onMouseClicked="#chooser"</code>.</p>