Skip to Content
Swing Hacks
book

Swing Hacks

by Joshua Marinacci, Chris Adamson
June 2005
Intermediate to advanced
544 pages
22h 24m
English
O'Reilly Media, Inc.
Content preview from Swing Hacks
Turn the Spotlight on Swing #64
Chapter 8, Rendering
|
329
HACK
The next step is to draw the shape containing the spotlights. Before doing
that, though, you need to compute the opacity of
mask. When you create a
new
Color
instance, you can define the opacity as a number between
0.0
(fully transparent), and
1.0
(fully opaque). To compute the required opac-
ity, the program first divides the area of the spotlights by the total area.
Thereby, if spotlights occupy 20% of the total area, you obtain the value 0.2.
Subtract this from 1.0 to compute the final opacity. In this example, the
opacity would be 0.8, or 80%.
The final step of the rendering depends on whether blurring is activated.
When blurring is off, the
mask is simply filled with shieldColor. Note that
the rendering hints defined in the constructor are used at this moment to
draw anti-aliased shapes. If blurring is activated, an extra step is required.
Instead of drawing the spotlights directly onto the glass pane’s graphics sur-
face, an offscreen buffer is created, with the same size as the panel itself.
After having drawn
mask on this offscreen buffer, the resulting picture is
drawn onto the panel’s graphics surface. All the magic happens when you
call the
drawImage( ) method with a ConvolveOp as the second parameter. The
method applies our blur filter on the picture while drawing it.
—Romain Guy
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Swing GUI Programming

Learning Swing GUI Programming

Brian Cole
Java Swing

Java Swing

Robert Eckstein, Marc Loy, Dave Wood
JFC Swing Tutorial, The: A Guide to Constructing GUIs, Second Edition

JFC Swing Tutorial, The: A Guide to Constructing GUIs, Second Edition

Kathy Walrath, Mary Campione, Alison Huml, Sharon Zakhour

Publisher Resources

ISBN: 0596009070Purchase bookErrata Page