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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started