2

So, i've set up a GUI that has a text field and a button. I have some images in my file, as shown below.Figure 1

Also this is the GUI; enter image description here

I wanna be able to input in the textField "A0" and it show (anywhere at this point) the image on the GUI. I'm not sure how to approch this, any help or example would be appreciated.

EDIT:

private void getImage(){
    char key;

    Image img = new Image("gui/assets/" + textField.getText() + ".png", 100, 100, false, false);

    ImageView image = new ImageView();
    image.setImage(img);
    image.setX(40);
    image.setY(480);
    pane.getChildren().add(image);
}

So this is what i've done (pane is just a group). Also, this is the primaryStage;

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("StepsGame Viewer");
    Scene scene = new Scene(root, VIEWER_WIDTH, VIEWER_HEIGHT);

    root.getChildren().add(controls);
    root.getChildren().add(pane);

    makeControls();

    primaryStage.setScene(scene);
    primaryStage.show();
}

So i added the group that adds the image into primaryStage, however when i input an image name e.g "A0", nothing comes up. What am i missing?

goat
  • 107
  • 8
  • Assuming your resources are set-up correctly, you can do something like `Image img = new Image("gui/assets/" + field.getText() + ".png");`. Then put the `Image` in an `ImageView` that's part of your UI. – Slaw May 07 '19 at 12:08
  • Okay, I've done that, please refer to the edit i have done in the question. – goat May 07 '19 at 12:55
  • 1
    Do you miss the `refreshButton.setOnAction(event -> getImage());` ? – Sunflame May 07 '19 at 15:24
  • @Sunflame Yes I did, it works now – goat May 08 '19 at 11:39
  • Or if you did expect, that it refreshes automatic when you type a valid name, you can use a listener on the `TextField.` – Sunflame May 09 '19 at 14:44
  • It would be ideal for it to do it automatic, not really sure what a listener is, how would I go about doing that? – goat May 11 '19 at 03:53

0 Answers0