File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Use of  JFileChooser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Use of  JFileChooser" Watch "Use of  JFileChooser" New topic
Author

Use of JFileChooser

pandu chinnu
Greenhorn

Joined: Nov 21, 2006
Posts: 16
Hi,

I want to open a file chooser by clicking the browse button. I have managed
to have a have a open dialog box which shows me all the directory of mycomputer. However when I select a file it dosen't show the path of the file in the text field next to the browse button. How do I select a file and implement action on it?

my code was as follows:

mani k
Greenhorn

Joined: Jul 12, 2006
Posts: 4
after selecting the file from your filechooser dialog,

tf.setText(chooser.getSelectedFile().getAbsolutePath();

(note : assuming tf is your text field reference)


ThAnKs<br /> <br />--<br />MaNi
pandu chinnu
Greenhorn

Joined: Nov 21, 2006
Posts: 16
Thanks, now it shows the path. However if I have to implement an action on the chosen text. Say I need to count the number of words in the chosen text document, how do I go about doing it? Say if I have a button name 'word count' . On pressing that button I have to implement an action listener. So we come to the listening method....how do we action on the selected text?

Thanks
mani k
Greenhorn

Joined: Jul 12, 2006
Posts: 4
try this,
import java.util.regex.*;
.......................
Pattern pat = Pattern.compile(<regexp> ;
Matcher match = pat.matcher(<file content> ;
int count = 0;
while(match.find()) {
count++;
}

note : <regexp> - pattern of your word to be counted
<file content> - you can match line by line of the file, or you
can make the file contents to stringbuffer

assumption : you are using jdk1.4 or more
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Use of JFileChooser
 
Similar Threads
Select directory with JFileChooser
file dialog
FileChooser.getSelected() turn into Blob
JFileChooser to select a drive
JFileChooser problem