Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-21-2007, 11:08 PM
Victor Victor is offline
Learning Programmer
 
Join Date: May 2007
Posts: 96
Rep Power: 6
Victor is on a distinguished road
Default jFileChooser

I made a File Chooser like this:
Code:
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int retVal = fc.showDialog(Main.this, "Select America's Army Directory");
However, I need to save the retVal (return value) as a string so I can use it. Any ideas?
__________________
Pegasus Homepage
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-22-2007, 09:54 AM
G_Morgan G_Morgan is offline
Guru
 
Join Date: Oct 2007
Age: 24
Posts: 506
Last Blog:
Just over the next hil...
Rep Power: 10
G_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura about
Default

The int returned is just a status flag. It tells you if the person clicked accept, cancel or if there was an error.

JFileChooser.showDialog()

Assuming you get JFileChooser.APPROVE_OPTION as the return type you can get the file from

JFileChooser.getSelectedFile()

Calling toString() on the returned file will give you the path you want.

Last edited by G_Morgan; 12-22-2007 at 09:57 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-22-2007, 10:52 AM
Victor Victor is offline
Learning Programmer
 
Join Date: May 2007
Posts: 96
Rep Power: 6
Victor is on a distinguished road
Default

Thank you, your advice was very helpful. But I still have 1 problem. When I ran the project after making some changes, it returned the name of the current folder. Ex. I was in My Documents and it only returned My Documents. Is there a way I can get the entire path? (Ex. 'C:/Documents and Settings/Victor/My Documents/')
Code:
final JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showDialog(Main.this, "Select America's Army Directory");
        if(returnVal == JFileChooser.APPROVE_OPTION) {
            String path = fc.getSelectedFile().getName();
            jTextField2.setText(path);
        }else{
         //Haven't filled in yet
        }
__________________
Pegasus Homepage
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-22-2007, 11:09 AM
G_Morgan G_Morgan is offline
Guru
 
Join Date: Oct 2007
Age: 24
Posts: 506
Last Blog:
Just over the next hil...
Rep Power: 10
G_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura about
Default

Try
File.getAbsolutePath()
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-22-2007, 11:18 AM
Victor Victor is offline
Learning Programmer
 
Join Date: May 2007
Posts: 96
Rep Power: 6
Victor is on a distinguished road
Default

Thank you very much, worked perfectly!
__________________
Pegasus Homepage
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -5. The time now is 03:00 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads