Preview ZIP and JAR Files #32
Chapter 4, File Choosers
|
167
HACK
With the code all in place, the running program will look like Figure 4-6.
As a nice enhancement, you could modify
ImagePreview to show previews of
other kinds of files (e.g., PDF or SVG). You could even preview text files by
showing the first few lines of the document. Because
setAccessory( ) lets
you set any
JComponent, you could create a panel that does something com-
pletely different, like connecting to a network drive, à la iDisk, or setting
import preferences like encoding and line endings.
H A C K
#32
Preview ZIP and JAR Files Hack #32
This hack will show you how to customize the file chooser to let users
navigate and load files from inside a ZIP or JAR file archive.
Most modern operating systems now have built-in support for compressed
files, usually in the form of ZIP files. You can open up a ZIP file and navi-
gate the contents from within the standard file browser or dialog box, all
without actually uncompressing anything. Surprisingly,
JFileChooser
doesn’t support ZIP files, even though Java has built-in ZIP support in the
java.util.zip package. And, since JAR files are in the same format, you get
two-for-one today!
Figure 4-6. A file chooser that previews images

Get Swing Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.