Sunday, September 14, 2008

Leopard-like toolbar buttons in Java Swing - part 2

I had been trying to create "leopard-like" toolbar buttons. This required a lot of Swing coding and a bit of imagination. Apple, with its Apple JDK 1.6 features, has introduced ways to create many different kinds of Apple buttons. Namely : square, gradient, bevel, textured, roundrect, recessed and help.
 This greatly reduces the work that you need to do. However, the look will not carry forward to other platforms. For that, you need to paint your own buttons as I mentioned in my earlier blog.
The technique for rendering leopard like toolbar button is :
  • Create a transparent PNG icon for the button - for example, a plus sign
  • Create a JButton and set button.putClientProperty("JButton.buttonType", "segmentedTextured") and various other options in apple's technical note website.


Monday, September 8, 2008

State of clientProperty in OS X Java 1.6

Started looking at my pet Java Swing application - jSpent. This time the attempt was to create a leopard-like unified toolbar. I was so excited to see that there is a clientProperty "apple.awt.brushMetalLook" - By setting this as : 
myFrame.getRootPane().putClientProperty("apple.awt.brushMetalLook", Boolean.TRUE);
This will cause OS X to render the title bar in the unified style. But unfortunately, there is no good clientProperty setting for the toolbar itself. So we end up with a light gray window title bar. The toolbar appears like a gray box, painted in different color. Not sure if this is a bug in Apples Java. However, I had to again resort to pick and choose and paint my own gradient just below the window title bar to make it look "Unified". So, here is the output. 


But oh well, I need to repaint the toolbar in ligher gradient when the window goes out of focus.. hm.. that's too much to do!