Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JFileChooser (choose Files Only)

 
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.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!