Displaying thumbnails as a grid
I have an application where I have to display images as t开发者_如何学编程humbnails in a grid and when the users click on one of them , the original picture should be displayed in JAVA. I dont have an
idea as to how to display the thumbnails present in the folder in the form of grid. Any help as to how to start and some sample codes and links would be welcome.Work on one thing at a time.
- Read about LayoutManagers and build a program that will lay out components in a grid.
- Figure out how to read images and create a thumbnail. Add that to your program.
- Mess with JDialog and creating popups. Also look at Action classes and ActionListeners to tie creating a popup to a button click.
Are you working in Swing? What part do you have problems with? If it's the layout, you can start with the GridLayout
Depending on how you want to implement the zoom, a Frame will be useful.
And to display the bitmaps, a Label will do.
If you need a JComponent, you can try a JTable. If you want a Layout, look at the GridLayout.
You can use Nebula Gallery Widget if you use SWT
I recently had the same requirement - and looked into using Flowlayout. Unfortunately - as this page here describes - http://tips4java.wordpress.com/2008/11/06/wrap-layout/ - it doesnt behave as we'd like.
Fortunately you can grab source for the 'WrapLayout' from the same page.
When it comes to loading images into your panel, for performance I recommend using a SwingWorker as explained here - http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html#efficiency
Have a look at JFlow it's not exactly what you were asking for but pretty close, and all done for you!
精彩评论