• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JFileChooser, FileDialog

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want that when i select a file from a specific location using JFileChooser then it must save the path of that file upto some location, so that next when i open JFileChooser Dialog to open some other file then i do not have to specify it the path of that file from the root, since they being in the same directory.
Same i want in the case of FileDialog also.
i hope that the problem is clear.
plz reply me soob
from hema
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For JFileChooser
JFileChooser chooser = new JFileChooser();
or
//set to the current directory
JFileChooser chooser =
new JFileChooser(System.getProperty("user.dir"));
Once the user selects a file, do the following

getParent() returns you a String while getParentFile() returns you a File object
For FileDialog
do following after the user selects a file
String dir = fd.getDirectory();
if (dir != null)
fd.setDirectory(dir);
[ January 24, 2002: Message edited by: kawaii desu ]
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kawaii that's detailed and good information.
Rashid
 
hema narayan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kawaii
for your detailed and
well explained answer to my problem
hema
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another easy way is to create JFileChooser at the start of application and keep this chooser until end of application.
public class blahblah {
private JFileChooser chooser = new JFileChooser;
// local public and private functions
} // end of application
since chooser has a class scope, it retains last selected directory/file information.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!