title: Open Image from FileChooser in JavaFX
body: <p>My program is supposed to upload a image from a file and then it displays that image as the background. My problem is that when I create an <code>Image</code> object in it's parameters it asks for the file which you are trying to put. I tried to putting my File object inside of its parameters and it's not working. Please help me. I'm Stuck.</p>
  
  <pre><code>public class FileOpener extends Application{
  
      public void start(final Stage stage) {
          stage.setTitle("File Chooser Sample");
  
          final FileChooser fileChooser = new FileChooser();
  
          final Button openButton = new Button("Choose Background Image");
          openButton.setOnAction((final ActionEvent e) -&gt; {
              File file = fileChooser.showOpenDialog(stage);
              if (file != null) {
                 // openFile(file);
  
                 // where my problem is 
                  Image image1 = new Image("file");
                  // what I tried to do
                      // Image image1 = new Image(file);
                  ImageView ip = new ImageView(image1);
                  BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, false);
                  BackgroundImage backgroundImage = new BackgroundImage(image1, BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, backgroundSize);
              }
          }); 
          final StackPane stac = new StackPane();       
          stac.getChildren().add(openButton);
          stage.setScene(new Scene(stac, 500, 500));
          stage.show();
      }  
  
       public static void main(String[] args) {
          Application.launch(args);
      }        
  }
  </code></pre>