Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser, FileDialog

 
hema narayan
Greenhorn
Posts: 6
  • 0
  • 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
 
Alex Ku
Ranch Hand
Posts: 47
  • 0
  • 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 ]
 
Rashid Ali
Ranch Hand
Posts: 349
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kawaii
for your detailed and
well explained answer to my problem
hema
 
suheel hussain
Greenhorn
Posts: 16
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic