title: How to display an image when a button is pressed in JavaFX
body: <p>I'm having trouble figuring out how to display an image when a button is pressed. Here's what I have so far:</p>
  
  <hr>
  
  <p>public class Flags extends Application {</p>
  
  <pre><code>@Override
  public void start(Stage primaryStage) {
     //Create a label to display a prompt
      Label promptLabel = new Label("Select Button to Display a Flag");
  
     //Create buttons to display the flags
      Button americanButton = new Button("American Flag");
      Button canadianButton = new Button("Canadian Flag");
      Button frenchButton = new Button("French Flag");
      Button germanButton = new Button("German Flag");
      Button mexicanButton = new Button("Mexican Flag");
  
  
      //Creating an HBox
      HBox hbox = new HBox(10, promptLabel);
      HBox hbox1 = new HBox(10, americanButton);
      HBox hbox2 = new HBox(10, canadianButton);
      HBox hbox3 = new HBox(10, frenchButton);
      HBox hbox4 = new HBox(10, germanButton);
      HBox hbox5 = new HBox(10, mexicanButton);
  
      americanButton.setOnAction(new AmericanButtonHandler());
  
  
      //Creating a VBox
      VBox vbox = new VBox(10, hbox, hbox1, hbox2, hbox3, hbox4, hbox5);
  
      //set vbox padding
      vbox.setPadding(new Insets(10));
  
      //set vbox alignment
      hbox.setAlignment(Pos.CENTER);
      //gridpane.setAlignment(Pos.CENTER);
      hbox1.setAlignment(Pos.CENTER);
      hbox2.setAlignment(Pos.CENTER);
      hbox3.setAlignment(Pos.CENTER);
      hbox4.setAlignment(Pos.CENTER);
      hbox5.setAlignment(Pos.CENTER);
  
      //Create a scene
      Scene scene = new Scene(vbox);
  
      primaryStage.setTitle("Flags");
      primaryStage.setScene(scene);
      primaryStage.show();
  }
  
  class AmericanButtonHandler implements EventHandler&lt;ActionEvent&gt;{
      @Override
      public void handle(ActionEvent event){
          Pane aPane = new HBox(10);
  
          //Create new image
          Image americanImage = new Image("file:America.png");
  
          //Create new imageView
          ImageView aImageView = new ImageView(americanImage);
  
          aImageView.setImage(americanImage);
      }
  }
  
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      launch(args);
  }
  </code></pre>
  
  <p>}</p>
  
  <hr>
  
  <p>So what I want to happen, is when the americanButton is pressed, the event handler is invoked allowing for the image to display. I've gotten to this point and can't seem to get passed it. Someone help!</p>