|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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"); |
| Sponsored Links |
|
|
|
|||
|
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. |
|
|||
|
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
}
|
|
|||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| 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 |