Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2004

Tip: Looking for answers? Try searching our database.

JFileChooser problem

Thread view: 
Robert Karlsson - 22 Apr 2004 05:54 GMT
 Hello,

I am using a JFileChooser in my application
to set the location where e certain file should
be saved.

Therefor I have set it to display directories only.

My problem is that the last selected folder is always
removed.

I assume I have missed som vital information but
I can not find out why.

Any help is highly appreciated.

The method is shown below.

 .:. rob

--[ code start ]--
protected static String getDirectory( MainFrame mf, File curDir ) {
  JFileChooser jfc    = new JFileChooser();
  jfc.setDialogTitle( "Set destination.." );
  jfc.setName( "Set destination" );
  jfc.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
  jfc.setApproveButtonToolTipText( "Set destination" );
  jfc.setApproveButtonText( "Ok" );
  jfc.setCurrentDirectory( curDir );

  int value = jfc.showSaveDialog( mf );

  if( value == JFileChooser.APPROVE_OPTION ) {
    return jfc.getCurrentDirectory().getPath();
  }

  return null;
}
--[ code end ]--
Robert Karlsson - 22 Apr 2004 05:58 GMT
[snip]
> My problem is that the last selected folder is always
> removed.

[snip]

For clarity:
With remove I mean that the String returned from
this method does not include the last selected folder.

 cheers, rob
Robert Karlsson - 22 Apr 2004 18:27 GMT
Problem solved, old stupid me
missed the obvious method in the api docs.

If anyone is interested, the code should read:

if( value == JFileChooser.APPROVE_OPTION ) {
  return jfc.getSelectedFile().toString();
}

 cheers, rob


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.