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

102
Chapter 3
C H A P T E R T H R E E
Tables and Trees
Hacks 21–27
A table component was one of the most obvious missing features in AWT,
and among the most welcome additions when Swing came out. However,
the
JTable may be used too much—it’s easy to throw an Object[][] at the
constructor and get a full-blown GUI table, and some developers don’t
question the wisdom of this sort of coding.
But despite the generosity of the Swing
JTable API, there are a few things
still missing. Wouldn’t it be nice if the table model keep itself sorted, or if
the column widths had a non-ugly default that takes their contents into
account? Well, you didn’t buy this book to argue API theory—the point
here is to hack things into shape. So, let’s get started.
H A C K
#21
Size Your Columns to Suit Your JTable’s
Contents Hack #21
A one-digit column does not need 100 pixels of dead space. You know this;
your JTables should, too.
Does Figure 3-1 look like your typical JTable?
Figure 3-1. JTable with default column sizing

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