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

Display Dates in a Custom Calendar #4
Chapter 1, Basic JComponents
|
19
HACK
The best thing about these image-based borders is that you can completely
change their look by just dropping in new images, which is easy to do with
the slice tool in Photoshop. When you create your own image borders, I rec-
ommend starting with a rectangular shape layer and then using filters and
effects to create drop shadows, bevels, and stroked borders.
H A C K
#4
Display Dates in a Custom Calendar Hack #4
You can download calendar components from third parties, but real hackers
can use Swing to build a custom calendar widget on their own.
When you design an application, you’ll often want to use standard widgets
to display information. Swing doesn’t always give you what you need,
though. Consider the calendar component: Swing doesn’t come with one, so
most users have to download widgets to integrate into their application.
However, why not go with a cool and hip teen-friendly application with an
attractive, image-based component, as shown in Figure 1-15?
That would be a bit more fun, wouldn’t it? This hack will show you how to
build a completely custom calendar component using
java.util.Calendar
and a few images.
First, consider what you’ll need. You’ve got to have pretty images, a compo-
nent to paint them on, and then some logic to handle the different parts of
the date, including what day of the week starts off the current month. You
should also provide a
setDate( ) method, so that MVC frameworks can play
well with your calendar. Let’s get started.
Figure 1-15. Custom calendar component

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