Here are some Swing links that you might have missed during this week:
- Jon Lipsky is back from a two-year long blogging hiatus and he writes about extending the RelativeLayout from James Elliott’s 2002 article.
- Santhosh Kumar is back as well (he’s not been blogging about Swing since last August), and this time he brings the auto-snap split pane divider. The solution is very simple, but i’m not sure of the usability of this particular feature. In the past, i always found the different auto-snap behaviors (such as windows in desktop managers or connectors in Visio) to stand in my way most of the time, leading me to fight with the UI. On the other hand, auto-snap in sliders is quite a useful features to restrict the input domain to a small discrete subset.
- JavaSwing.net continues its series of tutorials on Swing text components, and this time they write an introduction to working with JFormattedTextField component.
- Gregg Bolinger has an implementation of application wide hotkeys. It uses a custom EventQueue that inspects all KeyEvents and consumes those keystrokes that it sees as the custom hotkey launchers. If you decide to follow this route, be sure to read Hans Muller‘s post on the mailing list of AppFramework project from last October:
The downside is that I’ve spoken with the AWT technical lead and he’s suggested that using EventQueue.push() is deadlock-prone. That is, the area of code that deals with EventQueues is quite complex and there may be unknown bugs that could cause deadlocks.
- And finally, Ken Orr tracks an interesting problem of providing different visuals for controls in active and inactive windows. His solutions include checking Window.isFocused in various painting methods (such as JPanel.getBorder and JLabel.getForeground) and tracking the changes to “Frame.active” client property.
I’ve said before that the customers don’t care about the technology. To a certain extent, this is also true about the developers, especially when it comes to choosing the “right technology” for your next big project. If your team members have considerable experience with a specific technology, you’re much better off going with that instead of trying to learn the newest shiniest framework and making all the beginners’ mistakes (on the other hand, it never hurts to keep your eyes and mind open).
The case at hand – Woopra, the real-time Web tracking and analysis application. It has been called the Chuck Norris of Site Analytics and some promise that it will make you drool, and while a few reviews briefly mention that it is written in Java, nobody seems to care. And this is one of the best compliments the underlying technology can get – it is so good that you don’t even notice it. I’m not going to talk about Woopra’s features (although they are pretty nifty compared to Google Analytics). I’m just going to show a few screenshots that highlight the attention to visual details and the level of customization made possible in Swing. The live application feels great, with subtle animations, intuitive navigation and no UI freezes. Click on the thumbnails below to view the full size slideshow.




And while some ask if anyone really cares about desktop Java, others just use it to create good-looking and responsive applications.
Last week i talked about using Substance decoration painters to visually offset Flamingo ribbon component. Jonathan Giles asked a question in the comment sections on how hard would it be to apply these improvements to an application running under other (core or third-party look-and-feels). I did not wish to rush into implementing it, and let it simmer for a while. A few possible solutions presented themselves, some involving colorization on the UI delegate level, and some involving off-screen images and overriding one of the paint methods in the main component.
As expected, the simplest solution is also the most powerful, since it can be applied to any Swing component / container, involves a few lines of code and doesn’t require any changes in the component library. It uses the JXLayer wrapper developed by Alexander Potochkin and one of the filters from JHLabs project.
The JXLayer is a very powerful component that deserves much more attention that it has been getting over the past couple of years. It allows intercepting events, masking out some parts of the UI area, providing validation feedback, adding custom painting and much more. In our case, all we need to do is:
- Wrap the ribbon in a JXLayer
- Add a painter to that layer
- Create an image effect and add a rescale operation on it that shifts the colors towards light blue
- Add the effect to the painter
At this point, all the visuals from the ribbon will be shifted towards light blue color:

All this amounts to extra 8 lines of code, as shown in the new sample application shipping with the latest 3.1dev drop of Flamingo. While this requires extra two jars in your classpath, the solution is not only elegant, but also applicable to any Swing component / container.
The entry on translucent and shaped windows in Swing has generated quite a lot of discussion and interest. It appears that readers were interested in per-pixel translucency and soft clipping for shaped windows, and Anthony has provided a few tips on how to achieve this. So, pending an official guide / tutorial from the AWT team (hint hint), here is my take.

What you see here is a JWindow with soft-clipped top-left and top-right corner and pixel-level translucency in the bottom half. In addition to Anthony’s instructions, i have used the following:
The source code is here. I’m pretty sure that it’s not the best (and not the most readable), but it shows the potential. You’re more than welcome to use this code as a starting point (don’t forget to credit Chris, Romain and Sebastien if you’re reusing it).