Posted on Jan 14, 2009

Nimbus: The New Face of Swing – JavaOne 2008

I am just reviewing the submissions for JavaOne 2009 and was looking back at what we did for JavaOne 2008 and noticed Sun has posted the slides with audio from our session on Nimbus last year. So if you are interested in Nimbus and were not fortunate enough to be able to come and see us in person or have listened to it already. Then it is well worth checking out as I think we made a good attempt to explain how Nimbus works and how to use it. 

Nimbus: The New Face of Swing TS-6096

Presenter: Richard Bair, Sun Microsystems, Inc.; Jasper Potts, Sun Microsystems, Inc.

Nimbus is the stunning next-generation cross-platform look-and-feel for the Java platform, perfect for skinning Swing components in existing applications and new FX applications. In this session, two Nimbus developers guide you through using Nimbus to create beautiful modern applications. They cover the basics of using Nimbus in your Swing applications and also discuss using the new Nimbus Designer visual design tool for extending Nimbus and styling custom components. Finally, they show how to brand your applications with completely custom look-and-feels extending Nimbus.

Posted on Jan 6, 2009

Presenting on JavaFX at IJTC 2008 – Irish Java Technologies Conference 2008

Sorry for the very late notice but if you are attending IJTC on January 7th then I am giving a presentation on JavaFX at 3:30pm so hope to see you all there. I will be posting the slides and demos from this talk and the Devoxx ones later this week so keep an eye out. 

Speaker IJTC 2008

Posted on Dec 16, 2008

Learning the JavaFX Language

I had the pain of learning JavaFX by example code, following the compiler mailing list, asking people and if all else fails digging in the source. Finnaly there is a great article that has every thing you need to know to get you started with the language in one easy to read page:

Experiments With JavaFX Script

by Weiqi Gao, Principal Software Engineer

Its highly recommended reading and I wish it was around when I was learning JavaFX. Its in by bookmarks bar for quick reference every time I can’t remember a bit of syntax. Hope it helps you to.

Posted on Dec 15, 2008

Devoxx 2008

I attended Devoxx formally JavaPolis this year for the first time and had a truly brilliant experience. Probably worked the hardest I ever have in my life with about 4 hours of sleep a night for a week and non-stop between, but was also hugely enjoyable. It was great to have a chance to show JavaFX and feel the excitement we were generating around it. I finally got a chance to step back from the nitty details and try using it as a developer and see all the good points rather than the amount of work I still need to do to make everything perfect. Oh the pain of being a perfectionist :-) . As well as talking in several sessions on JavaFX and demoing in the keynote I got the chance to build a couple of applications in FX during the week. It was fun to see just how fast you can put cool looking apps together in FX:

  • Little image viewer app for our Java FX University session, I will post the source for this soon.
    FX Image Viewer
  • We had a demo called “Swish” which we were going to show during the JavaFX keynote at Devoxx, someone suggested would it not be cool if we could create a Devoxx themed version of it, expecting a logo somewhere or something like that. Well it gave me a chance to put the JavaFX Production Suite through its paces and see what we could do. So a few hours later we had a full Devoxx themed version. The swish demo takes a bunch of graphics created in Photoshop along with animation paths drawn in Illustrator and animates them to make a cool little visual demo. The cool thing is you can take completely new graphics files as long as they follow the same basic form and create a completely new version of the application with no code changes needed.
    Devox Swish
  • After showing Stephan Janssen he suggested how cool it would be if we could replace the full backdrop behind the slides on the cinema screen. So a  second minimal version of Devoxx Swish in full 1080p HD was born which was projected on the full Cinema screen while people were entering/exiting the keynote and when the Beatbox artist Roxorloops was performing.
    Devoxx Swish HD
  • Next I got asked if we could put together a little application for the Sun Booth to select prize winners from a text file of names, so a couple of hours later we had it up and running spinning and zooming random names when the mouse was clicked.
    Prize Draw
    Seemed to draw quite a crowd, or maybe it was just the cool prizes and free beer! :-)
    Prize Draw 2
  • When I was creating the prize draw application I needed to work out the Spline interpreter numbers to make the names thud down. I ended up using Romain Guy’s Spline Editor for Swing which makes it nice and easy. So thought it was about time we had a JavaFX version, and it could not be too hard. So a couple hours and a couple hundred bind statements later we have a very cool little Spline Editor that lets you edit the spline and see the effect in real time then copy the code to paste into your JavaFX application.
    Spline Editor
    If you would like to try it for your self click here:  you can also download the source Netbeans project.

I hope all of you who attended Devoxx this year had as much fun as I did and all of you who did not attend you really missed something great and hope to see you all there next year. I will be posting all the slides to our sessions here very soon. All the sessions were recorded and will be posted on www.parleys.com at some point next year.

Posted on Aug 27, 2008

Nimbus UIManager UIDefaults

Nimbus is completely configured by properties in the UIManager defaults table. In my last blog I showed a simple example of how to skin a single component. This gave you a sneak peek into the power of these properties. Lots of people have asked for a complete list of properties that can be set, well its simple just grab UIManager.getLookAndFeelDefaults() and iterate over the contents of the map and print the keys and values and there you go. Well I am not that cruel so I did the work for you and will include a link to a complete table of them at the end. But before I get to that let me explain how they work.

Nimbus properties follow some rules and you can not only use the property keys that we have added in as default but you can create your own. Nimbus Look and Feel scans the UIDefaults table when ever you add a property with UIManager.put(<<key>>,<<value>>) then updates its internal state. When that new property matches the current state of the component it applies to then it will be applied to that component. Properties cascade like CSS and the most specific matching one is used.
Example:

  • foreground = Color.BLACK
  • Label.foreground = Color.BLUE
  • Label[Disabled].foreground = Color.GRAY
  • "SomeLabel"[Disabled].foreground = Color.WHITE

In these examples foreground applies to the foreground of all regions of all components, Label.foreground applies to only Label components, Label[Disabled].foreground applies to only Label components in the Disabled state. "SomeLabel"[Disabled].foreground applies to all components named “SomeLabel” that are in the disabled state. Hopefully that also explains the different ways you can write a rule to match a Component. The only 2 cases that are not covered here are Component.Region.foreground which lets you specify a sub-region of a component and ComponentA:ChildComponentB.foreground which lets you specify a ChildComponentB contained within ComponentA. You can see many examples of these in the complete table below and then play with writing your own. For example you can use the “name” property of a component in a similar way to “class” in CSS, say naming a bunch of buttons “hotButton” and then specifying new rules for them in the defaults table. I already explained in my last blog how you can override the global defaults on a single instance bases which matches the “style” attribute with HTML CSS.

Colors in Nimbus are derived, which means there are a core set of colors which are constants and all the other colors are calculated from those. This means you can simply change those and the 1000s of other colors that are related and used in the painters will update to reflect the new base color. These colors are shown in the “Primary Colors” section of the table. The colors in the “Secondary Colors” section are derived from those in the “Primary Colors” section but themselves are used as the base colors for other colors. You may need to change the secondary colors to tweak the results of changing the primary ones if you are not happy with the results. You can you derived colors in your own code as well so that you colors can change when the primary colors change. This will allow you to make your application color theme-able idea for white label branding etc. The method you need is on NimbusLookAndFeel called getDerivedColor :

/**
 * Get a derived color, derived colors are shared instances and is color
 * value will change when its parent UIDefault color changes.
 *
 * @param uiDefaultParentName The parent UIDefault key
 * @param hOffset             The hue offset
 * @param sOffset             The saturation offset
 * @param bOffset             The brightness offset
 * @param aOffset             The alpha offset
 * @param uiResource          True if the derived color should be
 *                            UIResource, false if it should not be
 * @return The stored derived color
 */
public Color getDerivedColor(String uiDefaultParentName,
               float hOffset, float sOffset, float bOffset, int aOffset,
               boolean uiResource)

Hopefully the rest will make sense as you read though the table and look at all the examples. After that its just a matter of try playing with some and see what you can do. I hope you see that power in this that Richard Bair and I designed and hoped would be useful. The complete defaults properties table is way to big to include in this post so I have put it on a separate page.

If you would like to see how I made this list, here is the code that creates the html.

Java Icon
NimbusBrowser.java