• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in creating directory using JFileChooser(code included)

 
rachita mahendru
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear friend here is the code i had written but its not working
JFileChooser obj_FileChooser = new JFileChooser(".");
obj_FileChooser.setDialogTitle("Project files");
obj_FileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
iReturnVal = obj_FileChooser.showDialog(frame, "Save Project");
if(iReturnVal == obj_FileChooser.APPROVE_OPTION)
{
System.out.println("inside approve option");
str = obj_FileChooser.getSelectedFile().getPath();
f1 = obj_FileChooser.getSelectedFile();
int dot = str.indexOf(".");
if ( dot > 0 )
JOptionPane.showMessageDialog(frame,"You should specify the project name","Warning Message",JOptionPane.WARNING_MESSAGE);
else
{
f1.mkdir();
lv.projectname = str;
projecttf.setText(lv.projectname);
}
}
the code is not entering in the loop if i write a new string in the "filename" textfield of the JFileChooser. and hence i am unable to create a new directory with that name.
regards
rachita
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rachita,
In my opinion, you are using the JFileChooser incorrectly. As the name implies it is to be used to choose something. In your case you want them to type in some new, non-existing item and that is not the way the JFileChooser works. It requires that something in its' list be selected before moving on (either a directory or a file).
You will need to perform your function in 2 steps. Use the JFileChooser to specify the location for the new directory. Then use another textfield somewhere else to give the new directory a name and either a button or textfield listener to create the new project.
Regards,
Manfred.
 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,LEO is right,JFileChooser as the name suggests it is used to Choose a file/folder rather than to create them.U can very well use another field for the users to key-in the new folder's name.
Happy middling with java.
Netharam.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!