my dog learned polymorphism*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Use of  JFileChooser" Watch "Use of  JFileChooser" New topic

Use of JFileChooser

pandu chinnu

Joined: Nov 21, 2006
Posts: 16

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

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


(note : assuming tf is your text field reference)

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

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 do we action on the selected text?

mani k

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()) {

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
wood burning stoves
subject: Use of JFileChooser
Similar Threads
file dialog
Select directory with JFileChooser
FileChooser.getSelected() turn into Blob
JFileChooser to select a drive
JFileChooser problem