School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,029 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,089 people online right now. Registration is fast and FREE... Join Now!



file chooser

file chooser to put multiple file into the TextArea Rate Topic: -----

#1 qema_86  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 04-June 09


Dream Kudos: 0

Post icon  Posted 04 June 2009 - 05:27 PM

I had create the GUI program. I used the file chooser in my program. I want to select the multiple files so that all the files chosen is appear in the TextArea. My problem is, I can select the multiple file from the file chooser but after i click the open button, only one file is appear in the TextArea. Howcan I put the multiple files into the TextArea. Below is my code of the file chooser.



[code]
private void browse1ActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(true);
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFiles = fileChooser.getSelectedFile();
plain1.setText(selectedFiles.getName());
}
}
[/code
Was This Post Helpful? 0
  • +
  • -


#2 NeoTifa  Icon User is offline

  • 1-800-NEO-ROXS
  • Icon
  • View blog
  • Group: Authors
  • Posts: 7,596
  • Joined: 24-September 08


Dream Kudos: 150

Posted 04 June 2009 - 06:30 PM

Are you wanting to append the multiple files in the same area? (needed clarification)
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 04 June 2009 - 06:34 PM

You called the method that returns only 1 file
If multiple selections is enabled you should call the other one
 
// this return the first selected file
File selectedFile fileChooser.getSelectedFile();

// this one (notice the ending S) returns an arrayof the selected files
File[] selectedFile fileChoosergetSelectedFiles();

// then you can
for(File f : selectedFile) {
	textField.add(f);
}



hope this help
Was This Post Helpful? 0
  • +
  • -

#4 qema_86  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 04-June 09


Dream Kudos: 0

Posted 04 June 2009 - 07:29 PM

thanks for helping. I had try to put the code. but still not work. i tried to put the
plain1.add(f);
The plain1 is the TextArea.

You mean that the add function is to add the other files?
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 04 June 2009 - 07:51 PM

View Postqema_86, on 4 Jun, 2009 - 07:29 PM, said:

thanks for helping. I had try to put the code. but still not work. i tried to put the
plain1.add(f);
The plain1 is the TextArea.

You mean that the add function is to add the other files?


try
System.out.println("Number of file sleected: " + selectedFile.length());
for(int i = 0; i <  selectedFile.length; i++) {
	System.out.println("Adding: " + fileSelected[i] + " as file " + i);
	plain1.append(fileSelected[i].toString + "\n");
}


at least you'll see if you selected the good number of files and extracted their name correctly
not 100% sure what add(object) to a textArea does
Was This Post Helpful? 0
  • +
  • -

#6 qema_86  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 04-June 09


Dream Kudos: 0

Posted 11 June 2009 - 12:30 AM

tq pbl. you help me to solved it. i write my code as below and it's work

for (int i=0;i < selectedFiles.length;i++)
		
		plain1.append(selectedFiles[i].getName());
 

Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month