Question: Java Image Program using Java FX When I just opened a particular image with file chooser, I used the code below. It worked. When I

Java Image Program using Java FX

When I just opened a particular image with file chooser, I used the code below. It worked. When I tried to expand the program to choose a directory and list all the files in it, I figured I could use the same location = (selectedFile.getAbsoluteFile().toURI().toString()); It doesn't work. (Attached my code) What I'm trying to do is choose a directory with file chooser and capture the paths of all the jpg files into an array. I then have to display the images and be able to iterate through them.

What am I doing wrong?

//One image

if(event.getSource()==btnopen){

FileChooser UserImage = new FileChooser(); java.io.File selectedFile = UserImage.showOpenDialog(null); location = (selectedFile.getAbsoluteFile().toURI().toString()); img=new Image(location); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("Image Files (*.jpg)", "*.jpg"); UserImage.getExtensionFilters().add(extFilter); Object newStage; ************************************************************************************

// Trying to get the files from a directory and store the same path as the individual image.

public void listFiles(String dir){

myList = new ArrayList(); String extension = "jpg";

File directory = new File(dir);

//get all the files from a directory

File[] fList = directory.listFiles();

for (File file : fList){

if (file.isFile()){

if(files.endsWith(extension)) { java.io.File selectedFile = UserImage.showOpenDialog(null); location = (selectedFile.getAbsoluteFile().toURI().toString());

{

// Add files to an arrayList myList.add(files);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!