This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JFileChooser (choose Files Only)  RSS feed

 
shelly kalra
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi List,
I want my File chooser not to dispose when i choose a directory.I thought that
jImageFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
will work for me, but it isnt.
heres a part of my code
private String browseImageFile()
{
if(imageFilePath == null)
jImageFileChooser = new JFileChooser();
else
{
jImageFileChooser = new JFileChooser(imageFilePath);
}
jImageFileChooser.setAccessory(new ImagePreview(jImageFileChooser));
jImageFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
Vector ext = new Vector();
ext.add("gif");
ext.add("jpg");

Filter filter = new Filter(
ext, "Just Images(jpg/gif)");//i m adding a filter to let choose only gif/jpegs
jImageFileChooser.addChoosableFileFilter(filter);
jImageFileChooser.setDialogTitle("Add Image");
jImageFileChooser.setAcceptAllFileFilterUsed(false);
if (jImageFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
{
imageFilePath = new String();
int slashIndx = jImageFileChooser.getSelectedFile().toString().lastIndexOf(FileUtils.getSeperator());
imageFilePath = jImageFileChooser.getSelectedFile().toString().substring(0,slashIndx);
if(!jImageFileChooser.getSelectedFile().isFile())
return null;
else
return (jImageFileChooser.getSelectedFile()).toString();
}
else
return null;

}
At the moment, I m living with the alternative that when a directory is selected the jImageFileChooser.getSelectedFile().isFile() is false(however isDirectory() still doesnot give true!!),
and my function returns null but disposes the FileChooser dailog.
favour me by giving some info as to how get out of this problem
Thanks,
Shelly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!