Skip to main content

You Got What It Takes

Posted by editor on February 22, 2007 at 10:16 AM PST

If you can paint it, you can have it

One of the most beloved aspects of Swing is its infinite customizability. When presenting a JavaOne session on our Swing book, Josh Marinacci and I stuck to the catch-phrase "if you can paint it, you can have it." Actually, that's half the story -- the other half is "if you can model it, you can have it." Still, the point remains: if you can model some behavior with code, and use the various AWT, Swing, Java2D or even JOGL API's to put pixels into a Graphics2D, then you can create more or less anything.

It takes some prodding to get people past the built-in suite of Swing components. There's an "aha" moment when the young Swing developer figures out that while there's no canned tree-table component, a JTree can be wired to a JTable in various simple ways, using selection event listeners in the tree to drive changes in the table model. For the more ambitious, there's always Aerith as an extreme example of what's possible.

To get you on the road to customized Swing components, Substance creator Kirill Grouchnikov offers Feature Article today on
How to Write a Custom Swing Component. By way of example, he takes a new component concept introduced by Windows Vista and shows how to use Swing -- and in some cases re-use what it already gives you -- to achieve the same thing in Java:

This article will illustrate the process of creating a custom
component that is based on the new view slider from Microsoft
Windows Vista OS Explorer (see Figure 1). While this component
looks very much like a slider embedded in a pop-up menu, it has new
features that are not available on a regular JSlider. First, it has control points that have associated icons and labels.
In addition, while some ranges are contiguous (like Small Icons-Medium Icons) and allow continuous resizing of the file
icons, other ranges are discrete (like Tiles-Details).
When the value is in one of these ranges, the slider thumb can be
only at control points, and not inside the range.

Have a look, open your mind to what's possible, and go have some fun with Swing.

There's a remarkable accolade to note in Java Today.
The Canadian Broadcasting Corporation reports that James Gosling has been awarded Canada's highest civilian honor, the Order of Canada. The Order of Canada recognizes outstanding lifetime achievement and contributions to society and the country by Canadians from all walks of life. Gosling is one of 29 Canadians named Officers of the Order of Canada and will receive his insignia later in 2007.

Milestone 7 of NetBeans 6.0 (Dev) is now available for download. There is also an alternative way of installing M7 -- using NBI , the new NetBeans installation concept. M7 via NBI is available from the NBI page. Milestone 7 comes with many new features and improvements, including
Java Web Start support for J2SE Projects,
expression stepping in Debugger,
JBoss 5 support,
profiler Improvements,
local history and Subversion properties editor, and more.

DZone blogger Daniel Spiewak asks Does Swing Need Saving?
"There's been some discussion lately regarding various scripting languages and if they are (or aren't) the salvation for the "dying" Swing API (here, here and here). However, all of these blog entries assume one critical fact: Swing is dead or at least dying. I call that assumption into question.

In today's Weblogs, Stuart