O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preface
|
xv
How to Use This Book
You can read this book from cover to cover if you like, but each hack stands
on its own, so feel free to browse and jump to the different sections that
interest you most. If there’s a prerequisite you need to know about, a cross-
reference will guide you to the right hack. The code all works (we tried it)
but in case you can’t get a hack to work, let us know at the book’s web site:
http://www.oreilly.com/catalog/swinghks. You can also download the book’s
code online, or contribute your own tips and tricks. If we collect enough
new material, and this book sells more than 10 copies, then the publishers
might let us make Swing Hacks 2: The Endless Repaint.
With few exceptions, the hacks in this book were written for Java 2 Stan-
dard Edition (J2SE), version 1.4, which you can get from http://java.sun.com/
j2se/. A few hacks depend on open source packages, which are freely down-
loadable from their home pages, as described in the hack itself. The only
exceptions are two hacks that use QuickTime for Java—this is freely avail-
able from Apple (and installed by default on Mac OS X), but it is propri-
etary and available for Mac and Windows only.
Because this is a book about Swing, the program listings will be using the
classes from the Swing and AWT packages, so we’ve skipped
import javax.
swing.*
and import java.awt.* statements for space. You can also assume
that any listing involving event handling will
import java.awt.event.* and
probably import
javax.swing.event.* as well. Java2D hacks implicitly
import java.awt.image.*. In short, we’ll include import statements only
when a hack involves non-core, and/or non-obvious imports, like the hacks
that use JDBC, Lucene, Velocity, QuickTime for Java, etc.
How This Book Is Organized
The book is divided into several chapters, organized by subject:
Chapter 1, Basic JComponents
Here you’ll find simple hacks for the basic components like labels, but-
tons, and text fields. This chapter contains a lot of bang for the buck,
and it illustrates some of the techniques that we will explore more fully
later on. From fancy JLabels to translucent menus, this is a great place
to start.
Chapter 2, Lists and Combos
This chapter features complicated Swing components that are used
everywhere. Bend them to your will! Make them look good with poly-
morphic renderers and animated selections. Make them perform well
with filtering and Collections support.
xvi
|
Preface
Chapter 3, Tables and Trees
This chapter revelas the secrets of these mystic components—from
Excel exporting to proper JTree drop targets. Make the JTree and
JTable dance.
Chapter 4, File Choosers
One of Swing’s most maligned components, the JFileChooser, actually
has a lot of power hiding inside some murky APIs. This chapter will let
you use custom icons, detect Windows shortcuts, and even navigate ZIP
files.
Chapter 5, Windows, Dialogs, and Frames
This is where the fun begins. Every application needs a container, so
why not make it pretty and powerful? Make your windows drag and
snap. Build custom windows like the earthquake login and spin open
dialog. You can even save your window settings automatically with
almost no code changes.
Chapter 6, Transparent and Animated Windows
If you went through the previous chapter and still want more, then this
chapter is for you. We push windows to the limit with transparency,
animations, slide-in OS X stylesheets, and some of the coolest special
effects you’ve ever seen.
Chapter 7, Text
Text components seem boring, but there’s a lot of power hiding in
there. This chapter will show you how to do regular expression search-
ing, dot completion, backward text, and even three different ways to
give your application the bright sheen of anti-aliasing.
Chapter 8, Rendering
This chapter has the meat of the graphics hacks. Custom fonts, a magni-
fying glass, vector buttons, and even some work with Java3D. We’ve got
some great things to make your application pop.
Chapter 9, Drag-and-Drop
When your users want two pieces of software to work together the first
thing they want to do is drag-and-drop data from their other programs
to yours. This chapter covers how to do robust and attractive drag-and-
drop entirely within Java.
Chapter 10, Audio
What would be a cool modern application without some media sup-
port? This chapter covers four different ways to play sound, how to dis-
play waveforms, and how to embed MP3 support in your own
programs.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required