Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

JFileChooser, FileDialog

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The City calls upon her steadfast protectors. Now for a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic