Bringing Life to Swing Desktop Applications

Kirill Grouchnikov and Alexander Potochkin presented on advance Swing techniques at this JavaOne 2007 technical session. They talked about advanced painting and effects such as non-rectangular components, translucency, layering, image filtering and animation.

Custom components, especially non-rectangular components, should override the contains and paint methods. You can implement any effect on custom components by overriding these methods. By default, components are opaque. You can use opacity for transition effects, such as fading in and out of a container when tabs as selected. The reason you want to use visual effects is to indicate to the user a change in state, by nature Swing changes the UI immediately on an event.

In addition to adding effects to custom components and playing with opacity, Kirill talked about using a custom RepaintManager, and drawing on the glass pane. Customizing the RepaintManager allows you to control Swing’s component painting, for example to force a container to repaint child components. Drawing on the glass pane allows you to paint over all components. Kirill also suggested using JXPanel and JXLayer of the SwingX project from SwingLabs, these containers supports translucency, Painters API, image filtering, and non-rectangular components.

Kirill and Alexandar also talked about layering with UI delegates. Swing UI delegates are the classes responsible for painting Swing components, there exists one UI delegate for each component. As of current Java versions there are 41 UI delegates.

Kirill demoed some eye candy Swing effects, something he calls the ghost effects. Kirill has made available Rainbow, a SVG explorer application that demonstrates many of the techniques discussed in this session.

Technorati Tags: , , , , ,