Monday Jan 20, 2014

Options Window Color Analysis

So you're happily using JTattoo in your NetBeans Platform application. However, when you use the darker variations, such as "com.jtattoo.plaf.graphite.GraphiteLookAndFeel", you run into a problem. Though all the colors change as you'd expect... there's still the white background at the top of the Options window, as you can see below. 

That may seem like a small and insignificant problem. However, in the real world, Java and the NetBeans Platform are to be found in air traffic management and air traffic control systems, where the possibility of switching between a "day view" and a "night view", with all the related color updates, is not a "nice to have", but a "must".

So, the pesky white bar at the top of the Options window is a real problem in these real scenarios. A glaring white background is the very last thing you want in the Options window when the traffic controller has switched to "night view".

How to fix it? First, run the application from NetBeans IDE in Debug mode, open the Options window, and then click the orange camera button in the toolbar. Now a snapshot is made of the Options window and rendered in NetBeans IDE, where you can click on anything in the snapshot and see its related properties, such as the name of the panel where that white background is defined:

Then dig into the source code and find that panel. You now find that "Tree.background" is the relevant UIManager color for the white background in the Options window:

private static Color getTabPanelBackground() {
    if( isMetal || isNimbus ) {
        Color res = UIManager.getColor( "Tree.background" ); //NOI18N
        if( null == res )
            res = Color.white;
        return new Color( res.getRGB() );
    return Color.white;

Switch into your @OnStart annotated Runnable and use "Tree.background" as shown below:

public class Startable implements Runnable {
    public void run() {
        try {
            UIManager.put("Tree.background", Color.LIGHT_GRAY);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Startable.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        } catch (IllegalAccessException ex) {
        } catch (UnsupportedLookAndFeelException ex) {

And here's the Options window again, gone is the white background at the top:

Don't like the light gray color I set above? Fine, change it to another color. The point is that you now have control over that color and you also know how to figure out similar problems next time.





« January 2014 »