• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFileChooser + FileView = bad performance with Thumbnails

 
Peter Wolfenstein
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

My quest is to add the ability of a thumbnail view for jpg,gif and png images to JFileChooser, just like windows explorer.

So I created a FileView that reads and scales every image file and return it, so that the image is used as a icon for the file.

This works theoretically perfect, however I have huge performance problems. It seems as if all images are being loaded before they are displayed.

So before I can even open a folder, all images are read in and displayed.

Is there a way to solve this problem? I thought about Threads, but I couldn't find a way how to implement useful threading in this case.

Perfect would be a solution, that checks whether the file is being displayed or not and only loads the image when it is displayed.

Does anyone have a solution/idea to this one?
Does anyone know alternative FileChooser for Java which fulfill my requirements? (opensource/free would be nice)

Ty!
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Wolfenstein:
Hello!

My quest is to add the ability of a thumbnail view for jpg,gif and png images to JFileChooser, just like windows explorer.

So I created a FileView that reads and scales every image file and return it, so that the image is used as a icon for the file.

This works theoretically perfect, however I have huge performance problems. It seems as if all images are being loaded before they are displayed.

So before I can even open a folder, all images are read in and displayed.

Is there a way to solve this problem? I thought about Threads, but I couldn't find a way how to implement useful threading in this case.

Perfect would be a solution, that checks whether the file is being displayed or not and only loads the image when it is displayed.

Does anyone have a solution/idea to this one?
Does anyone know alternative FileChooser for Java which fulfill my requirements? (opensource/free would be nice)



You can always use the native file chooser (via FileDialog) if you
can live with its limitations. That's what I do when I can.

With JFileChooser, you would get better performance if you would
provide a preview of just the selected file.

To stick with FileView, I guess you could try returning a fixed icon
immediately and doing the loading/scaling in the background. You
would then have to figure out how to schedule a repaint.

Something else you could try is obtaining the actual JList that displays
the files (most LnFs use JList but there is no guarantee) and setting a
custom renderer on it. The motivation for that is that it would only
invoke the renderers it actually needed to show (something we would
expect to also be the case with FileView, but apparently not from
what you say). [edit: Let me make it clear that this would be
considered a hack.]
[ May 13, 2008: Message edited by: Brian Cole ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!