Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-05-2007, 01:47 PM
Member
 
Join Date: Dec 2007
Posts: 10
Mr tuition is on a distinguished road
JFileChooser remember the location
I'm trying to get the JFileChooser to remember the location of the previous location opened, and then next time open there, but is doesn't seem to remember.

I have tried to do this using the following method:

jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(jButton2);
if (theOutString != null){
fc.setCurrentDirectory(new File(theOutString)); }
if(returnVal == JFileChooser.APPROVE_OPTION) {
theOutString = fc.getSelectedFile().getName();
theOutString = fc.getSelectedFile().getPath();
System.out.println("You chose to open this file: " + theOutFile);
jTextField1.setText(theOutString);
}
}

private String theOutString;
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-05-2007, 08:24 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Make the JFileChooser a member variable and instantiate it only one time then it will remember where to appear and the last user–selected directory.
Code:
class Pseudo { JFileChooser fc; Pseudo() { fc = new JFileChooser("."); } jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int returnVal = fc.showOpenDialog(jButton2); ...
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-08-2007, 05:16 PM
Member
 
Join Date: Dec 2007
Posts: 10
Mr tuition is on a distinguished road
But it wouldn’t remember where to appear each time you run this application would it? just while you are running it?


I ended up using a file reader and write to save a "cookie" type file, to remember the location, then try to read it in, if successful (Location2 != null)



PHP Code:
 if (Location2 != null){  fc.setCurrentDirectory(new File(Location2)); }
                
int returnVal fc.showOpenDialog(jButton2);
                 if(
returnVal == JFileChooser.APPROVE_OPTION) {
                
theOutString fc.getSelectedFile().getName();
                 
theOutString fc.getSelectedFile().getPath();            
                
                
jTextField1.setText(theOutString);
                } 
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-08-2007, 07:17 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
But it wouldn’t remember where to appear each time you run this application would it? just while you are running it?
Right.
For persistence try Using the Preferences API.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Localize JFileChooser Java Tip Java Tips 0 03-14-2008 01:54 PM
how to use JFileChooser tommy New To Java 1 08-06-2007 10:49 PM
how to get the location of some button mary Java 2D 2 08-05-2007 06:02 AM
how to have function variables remember their values between calls asterik123 New To Java 2 08-03-2007 06:06 PM
Location Based Application pablodaroucchi Java Books / Tutorials / Tips 1 04-22-2007 12:59 AM


All times are GMT +3. The time now is 03:26 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org