0

I have gotten the program to allow me to browse for a file to select using the file chooser. You will see the method for this in my code below. My problem is that I do not know what to do next. I want to assign the file chosen as an image file. I then want to display the image(only image files will be used in this program).

Since I am using scene builder, which contains the actual application(Paint) class as well as the FXML controller class, I believe I will have to add code to both classes. I have attached both for clarity sake.

public class FXMLDocumentController implements Initializable {


@FXML
private MenuItem open;
private MenuItem exit;
private AnchorPane pane;
private ImageView imgv;
private Stage primaryStage;


@FXML
private void handleOpenAction() {

    FileChooser fileChooser = new FileChooser();
    FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
    FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
    File file = fileChooser.showOpenDialog(primaryStage);


}
@FXML
private void handleExitAction(){
            System.exit(0);

}


@Override
public void initialize(URL url, ResourceBundle rb) {

}    



}


public class Paint extends Application {

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
    Scene scene = new Scene(root, 400, 600);
    stage.setTitle("Paint");
    stage.setScene(scene);
    stage.show();


    }

public static void main(String[] args) {
    launch(args);
}

I don't mind loading the image into the default program pane, however I must be able to "draw" on the image later on down the road.

  1. How do I get/set the image selected via filechooser?
    • Do I do this inside the same FXML method or make a separate method?
  2. How do I display the image?
    • Should I be creating the pane that the image will load into manually inside the FXML class or inside the Paint class?
  3. Is there a way to create a (choose, get, set) method that I could add to the Paint class that can be referenced from inside the FXML class?

  4. I am aware that I must assign the scene builder elements to the fxml handles/methods for them to function properly.

mipa
  • 10,369
  • 2
  • 16
  • 35
Ted
  • 65
  • 1
  • 11
  • fabian where is the question that this question duplicates. I have not seen it as I would not have asked if I had. Thanks – Ted Sep 11 '17 at 19:50
  • Your question seems pretty much identical to the first one listed as a duplicate. If you think it is substantially different, you probably need to explain in what way it is different. – James_D Sep 11 '17 at 20:04
  • I found where it lists the question that is being referenced. I have actually seen this question, however cannot seem to integrate that answer with what I need. – Ted Sep 11 '17 at 20:19

0 Answers0