• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Use of JFileChooser

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after selecting the file from your filechooser dialog,

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

(note : assuming tf is your text field reference)
 
pandu chinnu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic